Skip to content
Snippets Groups Projects

Draft: Improve permission checks and logic

1 open thread
  • Fix rolify with_role to be combineable into larger queries without using .ids
  • Add option to define rolify relations easily as has_many relations on models.
  • Update associatable with the increased flexibility to let ActiveRecord combine queries better.
  • Make use of hashes rather than .ids in the ability to prevent queries on load and allow CanCanCan to do its job better
  • Add extension to CanCanCan to allow joining can definitions with scopes together

TODO:

  • Check whether using .select(:id) in the ability makes better queries than the left-over id: ....ids.
  • Check performance of new roles queries (left outer join) and determine whether its better to use scopes.
  • Convert more of the ability file to use scopes.

Relates to #81

Edited by Taico Aerts

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
25 # Creates a `has_many` relation with the given name which returns an ActiveRecord::Relation of User.
26 # Additionally, a `has_many` association_name_roles will be made which returns an ActiveRecord::Relation of UsersRole.
27 #
28 # @param association_name [Symbol] the name of the association to add
29 # @param name_or_code [String, Symbol, Array, Proc, Lambda, Nil] the name of the role to add or a lambda to pass to the association (Default: all)
30 def relate_users_role(association_name, name_or_code = nil)
31 if name_or_code.nil?
32 has_many association_name,
33 through: :roles,
34 class_name: User.model_name.name,
35 source: :users
36 has_many "#{association_name}_roles".to_sym,
37 through: :roles,
38 class_name: UsersRole.model_name.name,
39 source: :users_roles
40 elsif name_or_code.is_a?(String) || name_or_code.is_a?(Symbol) || name_or_code.is_a?(Array)
  • Taico Aerts changed the description

    changed the description

  • Taico Aerts requested review from @mmladenov

    requested review from @mmladenov

  • Taico Aerts added 170 commits

    added 170 commits

    • 9898b106...36c50f37 - 159 commits from branch development
    • e8e4aff4 - Merge branch 'development' into optimizations
    • cf932dab - Remove unnecessary role authorization checks
    • 2d2b0b30 - Fix leaving not possible even with 2 users in company
    • b528db85 - Prevent possible future issues for role invitations on groups which are not CSRs
    • 12b6005c - Use safe navigation to prevent 500 error for invalid request
    • a69888b1 - Update message
    • 6fbc8a36 - Relate research group roles
    • 2fefd09d - Add not_inactive? scope for CE
    • b3820f57 - Load invitations without id
    • 2aea529d - Merge show and join for company allow to join
    • 3eb0383f - Restructure ability

    Compare with previous version

  • Taico Aerts marked the checklist item Check whether using .select(:id) in the ability makes better queries than the left-over id: ....ids. as completed

    marked the checklist item Check whether using .select(:id) in the ability makes better queries than the left-over id: ....ids. as completed

  • Taico Aerts marked the checklist item Convert more of the ability file to use scopes. as completed

    marked the checklist item Convert more of the ability file to use scopes. as completed

  • Taico Aerts added 4 commits

    added 4 commits

    • 489ffbb0 - Cleanup + fix exists?/include? usage
    • 10766b71 - Fix rubocop
    • 4e2b14f2 - Fix unused argument
    • 61cb33ef - Switch to and rather than merge to fix deprecation

    Compare with previous version

  • Taico Aerts added 1 commit

    added 1 commit

    Compare with previous version

  • Taico Aerts added 1 commit

    added 1 commit

    Compare with previous version

  • Taico Aerts added 4 commits

    added 4 commits

    • f3df55b2 - Fix scoped can secondary usage
    • f38814f2 - Fix logic for hash and raw sql
    • 74347048 - Use latest of cancancan to disable rules compression
    • 7276b6cf - Fix and back into merge

    Compare with previous version

  • Taico Aerts added 3 commits

    added 3 commits

    Compare with previous version

  • Taico Aerts added 301 commits

    added 301 commits

    Compare with previous version

  • Taico Aerts added 21 commits

    added 21 commits

    Compare with previous version

  • The ability file contains a special section for unconfirmed employees. However, this appears to be unnecessary, as the regular offerer section automatically also applies to unconfirmed employees. user.offerer_projects also includes all projects which the user has a client role on.

  • Please register or sign in to reply
    Loading