diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-07-14 14:58:53 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-07-14 14:58:53 +0400 |
commit | 2099aa38b661f7ceacb1346c1199b9dd89c7dec0 (patch) | |
tree | 6d019c911589fb1090a32052050a99d22b7ecc6f | |
parent | c50f89519660a7da6e9c7978118a29a7a45178c6 (diff) | |
parent | 8ec02ed9aa36160bd19155cef1f71ca7e12ad4f3 (diff) |
Merge pull request #7131 from skv-headless/per_request_rules_caching
per request project rules caching
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | Gemfile.lock | 2 | ||||
-rw-r--r-- | app/models/ability.rb | 50 |
3 files changed, 29 insertions, 24 deletions
@@ -173,6 +173,7 @@ gem "font-awesome-rails", '~> 3.2' gem "gitlab_emoji", "~> 0.0.1.1" gem "gon", '~> 5.0.0' gem 'nprogress-rails' +gem 'request_store' group :development do gem "annotate", "~> 2.6.0.beta2" diff --git a/Gemfile.lock b/Gemfile.lock index 97d3d8bab64..363987bea12 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -409,6 +409,7 @@ GEM redis-store (1.1.4) redis (>= 2.2) ref (1.0.5) + request_store (1.0.5) require_all (1.3.2) rest-client (1.6.7) mime-types (>= 1.16) @@ -647,6 +648,7 @@ DEPENDENCIES rb-inotify redcarpet (~> 2.2.2) redis-rails + request_store rspec-rails sanitize (~> 2.0) sass-rails (~> 4.0.2) diff --git a/app/models/ability.rb b/app/models/ability.rb index 234578b5e18..d33ca41118a 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -67,40 +67,42 @@ class Ability def project_abilities(user, project) rules = [] + key = "/user/#{user.id}/project/#{project.id}" + RequestStore.store[key] ||= begin + team = project.team - team = project.team + # Rules based on role in project + if team.master?(user) + rules += project_master_rules - # Rules based on role in project - if team.master?(user) - rules += project_master_rules + elsif team.developer?(user) + rules += project_dev_rules - elsif team.developer?(user) - rules += project_dev_rules + elsif team.reporter?(user) + rules += project_report_rules - elsif team.reporter?(user) - rules += project_report_rules + elsif team.guest?(user) + rules += project_guest_rules + end - elsif team.guest?(user) - rules += project_guest_rules - end + if project.public? || project.internal? + rules += public_project_rules + end - if project.public? || project.internal? - rules += public_project_rules - end + if project.owner == user || user.admin? + rules += project_admin_rules + end - if project.owner == user || user.admin? - rules += project_admin_rules - end + if project.group && project.group.has_owner?(user) + rules += project_admin_rules + end - if project.group && project.group.has_owner?(user) - rules += project_admin_rules - end + if project.archived? + rules -= project_archived_rules + end - if project.archived? - rules -= project_archived_rules + rules end - - rules end def public_project_rules |