Added permissions to badges #36

Open
bruncbrunc wants to merge 3 commits from badge into master
bruncbrunc commented 2017-07-11 17:21:12 +00:00 (Migrated from github.com)
No description provided.
jomo (Migrated from github.com) reviewed 2017-08-06 03:52:46 +00:00
jomo (Migrated from github.com) commented 2017-08-06 03:41:00 +00:00

whar are these for?

whar are these for?
jomo (Migrated from github.com) commented 2017-08-06 03:48:57 +00:00

please don't shorten any text limits

please don't shorten any text limits
jomo (Migrated from github.com) requested changes 2017-08-06 17:02:16 +00:00
jomo (Migrated from github.com) left a comment

You can throw away half of your code and just use collection_check_boxes 😎

Other than that, if I'm not mistaken you should be able to use something like

@forum.badges.create!(badge: b, permission: p)

and

@forum.badges.find_by(id: b, permission: p)

Also, you can use

Badge.where.not(name: "none")
You can throw away half of your code and just use [`collection_check_boxes`](https://makandracards.com/makandra/32147-rails-4-introduced-collection_check_boxes) :sunglasses: Other than that, if I'm not mistaken you should be able to use something like ```ruby @forum.badges.create!(badge: b, permission: p) ``` and ```ruby @forum.badges.find_by(id: b, permission: p) ``` Also, you can use ```ruby Badge.where.not(name: "none") ```
@ -88,3 +88,3 @@
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))
if query
jomo (Migrated from github.com) commented 2017-08-06 16:23:15 +00:00

Couldn't you just use forum.can_read?

Couldn't you just use `forum.can_read`?
jomo (Migrated from github.com) commented 2017-08-06 16:23:23 +00:00

Since this results in:

  • OR (true) (which will always match) or
  • OR (false) (which will have no effect on the current query)

you could just wrap the query in a condition and not filter them any further.
Also, given that (#{can_read}) just mimics forum.can_read? in the SQL query, you don't need to include it anymore:

unless forum.can_read?(user)
  threads = threads.where("forumthreads.user_author_id = ? OR (#{sticky_can_write})", user_id, role_value, role_value)
end
Since this results in: - `OR (true)` (which will always match) or - `OR (false)` (which will have no effect on the current query) you could just wrap the query in a condition and not filter them any further. Also, given that `(#{can_read})` just mimics `forum.can_read?` in the SQL query, you don't need to include it anymore: ```ruby unless forum.can_read?(user) threads = threads.where("forumthreads.user_author_id = ? OR (#{sticky_can_write})", user_id, role_value, role_value) end ```
@ -29,12 +29,28 @@
<td><%= f.label :role_read_id, "Min. read role" %></td>
jomo (Migrated from github.com) commented 2017-08-06 15:29:11 +00:00

You could use f.check_box instead, this would also generate a proper label tag.

You could use [`f.check_box`](http://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-check_box) instead, this would also generate a proper label tag.
bruncbrunc commented 2017-08-06 17:04:58 +00:00 (Migrated from github.com)

where.not, if I'm not mistaken, was added in rails 5. We are using rails 4.

where.not, if I'm not mistaken, was added in rails 5. We are using rails 4.
jomo commented 2017-08-06 17:11:15 +00:00 (Migrated from github.com)
Loading development environment (Rails 4.2.5.1)
irb(main):001:0> Badge.where.not(name: :none)
  Badge Load (0.4ms)  SELECT `badges`.* FROM `badges` WHERE (`badges`.`name` != 'none')
┌────┬───────────┬────────┬───────┬───────┐
│ id │ name      │ symbol │ color │ value │
├────┼───────────┼────────┼───────┼───────┤
│ 2  ╎ donor     ╎ $      ╎ #f60  ╎       │
│ 3  ╎ developer ╎ D      ╎ #a0a  ╎       │
│ 4  ╎ retired   ╎ R      ╎ #0aa  ╎       │
│ 5  ╎ lead      ╎ L      ╎ #a00  ╎       │
└────┴───────────┴────────┴───────┴───────┘
4 rows in set
```irb Loading development environment (Rails 4.2.5.1) irb(main):001:0> Badge.where.not(name: :none) Badge Load (0.4ms) SELECT `badges`.* FROM `badges` WHERE (`badges`.`name` != 'none') ┌────┬───────────┬────────┬───────┬───────┐ │ id │ name │ symbol │ color │ value │ ├────┼───────────┼────────┼───────┼───────┤ │ 2 ╎ donor ╎ $ ╎ #f60 ╎ │ │ 3 ╎ developer ╎ D ╎ #a0a ╎ │ │ 4 ╎ retired ╎ R ╎ #0aa ╎ │ │ 5 ╎ lead ╎ L ╎ #a00 ╎ │ └────┴───────────┴────────┴───────┴───────┘ 4 rows in set ```
bruncbrunc commented 2017-08-06 17:12:37 +00:00 (Migrated from github.com)

In that case I have no clue, but I definitely wasn't able to do that when I was a developer.

In that case I have no clue, but I definitely wasn't able to do that when I was a developer.
This repo is archived. You cannot comment on pull requests.
No reviewers
No Milestone
No Assignees
1 Participants
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Redstoner/redstoner.com#36
No description provided.