diff options
author | http://jneen.net/ <jneen@jneen.net> | 2016-08-16 16:46:35 -0700 |
---|---|---|
committer | http://jneen.net/ <jneen@jneen.net> | 2016-08-30 11:39:22 -0700 |
commit | 29059c2e9c7be418d2a99a136934c6d9cca5fccd (patch) | |
tree | 4c54f77bd0df3078c6820e045298493c360b3221 /app/policies | |
parent | 9a0ea1350131368b9b723f1a9581bbfffe7c43f8 (diff) | |
download | gitlab-ce-29059c2e9c7be418d2a99a136934c6d9cca5fccd.tar.gz |
add personal snippets and project members
Diffstat (limited to 'app/policies')
-rw-r--r-- | app/policies/personal_snippet_policy.rb | 16 | ||||
-rw-r--r-- | app/policies/project_member_policy.rb | 22 |
2 files changed, 38 insertions, 0 deletions
diff --git a/app/policies/personal_snippet_policy.rb b/app/policies/personal_snippet_policy.rb new file mode 100644 index 00000000000..46c5aa1a5be --- /dev/null +++ b/app/policies/personal_snippet_policy.rb @@ -0,0 +1,16 @@ +class PersonalSnippetPolicy < BasePolicy + def rules + can! :read_personal_snippet if @subject.public? + return unless @user + + if @subject.author == @user + can! :read_personal_snippet + can! :update_personal_snippet + can! :admin_personal_snippet + end + + if @subject.internal? && !@user.external? + can! :read_personal_snippet + end + end +end diff --git a/app/policies/project_member_policy.rb b/app/policies/project_member_policy.rb new file mode 100644 index 00000000000..1c038dddd4b --- /dev/null +++ b/app/policies/project_member_policy.rb @@ -0,0 +1,22 @@ +class ProjectMemberPolicy < BasePolicy + def rules + # anonymous users have no abilities here + return unless @user + + target_user = @subject.user + project = @subject.project + + return if target_user == project.owner + + can_manage = Ability.allowed?(@user, :admin_project_member, project) + + if can_manage + can! :update_project_member + can! :destroy_project_member + end + + if @user == target_user + can! :destroy_project_member + end + end +end |