-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added permissions to badges #36
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Badgeassociation < ActiveRecord::Base | ||
|
||
belongs_to :badge | ||
belongs_to :forum | ||
belongs_to :forumgroup | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ def self.filter (user, title, content, reply, label, author, query, forum) | |
order_phrase = query || [title, content, reply].select(&:present?).join(" ") | ||
user_id = user.try(:id).to_i | ||
role_value = user.try(:role).to_i | ||
can_read = "COALESCE(forum_role_read.value, 0) <= ? AND COALESCE(forumgroup_role_read.value, 0) <= ?" | ||
can_read = "(COALESCE(forum_role_read.value, 0) <= ? AND COALESCE(forumgroup_role_read.value, 0) <= ?)" | ||
# A user can view sticky threads in write-only forums without read permissions. | ||
sticky_can_write = "sticky = true AND (COALESCE(forum_role_write.value, 0) <= ? AND COALESCE(forumgroup_role_write.value, 0) <= ?)" | ||
match = ["MATCH (title, forumthreads.content) AGAINST (#{Forumthread.sanitize(order_phrase)})", "MATCH (threadreplies.content) AGAINST (#{Forumthread.sanitize(order_phrase)})", "MATCH (title, forumthreads.content) AGAINST (?) OR MATCH (threadreplies.content) AGAINST (?)", "MATCH (title) AGAINST (?)", "MATCH (forumthreads.content) AGAINST (?)", "MATCH (threadreplies.content) AGAINST (?)"] | ||
|
@@ -86,7 +86,7 @@ def self.filter (user, title, content, reply, label, author, query, forum) | |
.joins("LEFT JOIN roles as forumgroup_role_read ON forumgroups.role_read_id = forumgroup_role_read.id") | ||
.joins("LEFT JOIN roles as forumgroup_role_write ON forumgroups.role_write_id = forumgroup_role_write.id") | ||
|
||
threads = threads.where("forumthreads.user_author_id = ? OR (#{can_read}) OR (#{sticky_can_write})", user_id, role_value, role_value, role_value, role_value) | ||
threads = threads.where("forumthreads.user_author_id = ? OR (#{can_read}) OR (#{sticky_can_write}) OR (?)", user_id, role_value, role_value, role_value, role_value, Forum.find(forum).can_read?(user)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Couldn't you just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this results in:
you could just wrap the query in a condition and not filter them any further. unless forum.can_read?(user)
threads = threads.where("forumthreads.user_author_id = ? OR (#{sticky_can_write})", user_id, role_value, role_value)
end |
||
if query | ||
threads = threads.where("#{match[2]}", query[0..99], query[0..99]) | ||
elsif [title, content, reply].any? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,12 +29,28 @@ | |
<td><%= f.label :role_read_id, "Min. read role" %></td> | ||
<td><%= f.select :role_read_id, role_selection, include_blank: "None" %></td> | ||
</tr> | ||
<tr> | ||
<td><b>Badges with read permission</b></td> | ||
<td> | ||
<% Badge.where("name != 'none'").each do |b| %> | ||
<%=b%><%= check_box_tag "read-#{b}", nil, Badgeassociation.find_by(badge: b, forumgroup: @group, permission: 1) %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use |
||
<% end %> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td><%= f.label :role_write_id, "Min. write role" %></td> | ||
<td><%= f.select :role_write_id, role_selection, include_blank: false %></td> | ||
</tr> | ||
<tr> | ||
<td><b>Badges with write permission</b></td> | ||
<td> | ||
<% Badge.where("name != 'none'").each do |b| %> | ||
<%=b%><%= check_box_tag "write-#{b}", nil, Badgeassociation.find_by(badge: b, forumgroup: @group, permission: 2) %> | ||
<% end %> | ||
</td> | ||
</tr> | ||
</table> | ||
<p><%= f.submit "Update group", class: "btn blue left" %></p> | ||
<% end %> | ||
<p><%= button_to "Delete group", @group, :method => "delete", data: {confirm: "Delete group?\nForums + Threads will not be accessible!"}, class: "btn red right" %></p> | ||
<div class="clear"></div> | ||
<div class="clear"></div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateBadgeassociations < ActiveRecord::Migration | ||
def change | ||
create_table :badgeassociations do |t| | ||
t.references :badge | ||
t.references :forum | ||
t.references :forumgroup | ||
t.integer :permission #1 = read, 2 = write | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whar are these for?