diff options
| author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-09-24 15:58:39 +0300 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-09-24 15:58:39 +0300 |
| commit | 66998f6d46ee778e6bde749e41f1d712b184a771 (patch) | |
| tree | 6b81a984cdc61ed084bdceeaf2876eaa250cf75d /app/models/ability.rb | |
| parent | e894e3eea505ebd675b90c3c53382fd8f273ced8 (diff) | |
| download | gitlab-ce-66998f6d46ee778e6bde749e41f1d712b184a771.tar.gz | |
Allow non authenticated user access to public projects
Diffstat (limited to 'app/models/ability.rb')
| -rw-r--r-- | app/models/ability.rb | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/app/models/ability.rb b/app/models/ability.rb index 8335829f919..7f044b220a5 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -1,6 +1,7 @@ class Ability class << self def allowed(user, subject) + return not_auth_abilities(user, subject) if user.nil? return [] unless user.kind_of?(User) return [] if user.blocked? @@ -17,6 +18,24 @@ class Ability end.concat(global_abilities(user)) end + # List of possible abilities + # for non-authenticated user + def not_auth_abilities(user, subject) + project = if subject.kind_of?(Project) + subject + elsif subject.respond_to?(:project) + subject.project + else + nil + end + + if project && project.public + public_project_rules + else + [] + end + end + def global_abilities(user) rules = [] rules << :create_group if user.can_create_group @@ -58,19 +77,9 @@ class Ability end def public_project_rules - [ + project_guest_rules + [ :download_code, :fork_project, - :read_project, - :read_wiki, - :read_issue, - :read_milestone, - :read_project_snippet, - :read_team_member, - :read_merge_request, - :read_note, - :write_issue, - :write_note ] end |
