refactor manage repository permissions

This commit is contained in:
mlorb 2017-12-13 11:09:25 +01:00
parent 2918a9833d
commit 7c1ae6bc82
5 changed files with 37 additions and 41 deletions

View file

@ -8,10 +8,8 @@ class RepositoriesController < ApplicationController
before_action :check_view_permissions, only: :export_repository
before_action :check_edit_and_destroy_permissions, only:
%i(destroy destroy_modal rename_modal update)
before_action :check_copy_permissions, only:
%i(copy_modal copy)
before_action :check_create_permissions, only:
%i(create_new_modal create)
%i(create_new_modal create copy_modal copy)
def index
render('repositories/index')
@ -307,15 +305,12 @@ class RepositoriesController < ApplicationController
end
def check_create_permissions
render_403 unless can_create_repository(@team)
render_403 unless can_manage_repository?(@team) ||
@team.repositories.count < Constants::REPOSITORIES_LIMIT
end
def check_edit_and_destroy_permissions
render_403 unless can_edit_and_destroy_repository(@repository)
end
def check_copy_permissions
render_403 unless can_copy_repository(@repository)
render_403 unless can_manage_repository?(@team)
end
def repository_params

View file

@ -1046,22 +1046,22 @@ module PermissionHelper
# is_member_of_team(team)
# end
def can_create_repository(team)
is_admin_of_team(team) &&
team.repositories.count < Constants::REPOSITORIES_LIMIT
end
# def can_create_repository(team)
# is_admin_of_team(team) &&
# team.repositories.count < Constants::REPOSITORIES_LIMIT
# end
# def can_view_repository(repository)
# is_member_of_team(repository.team)
# end
def can_edit_and_destroy_repository(repository)
is_admin_of_team(repository.team)
end
# def can_edit_and_destroy_repository(repository)
# is_admin_of_team(repository.team)
# end
def can_copy_repository(repository)
can_create_repository(repository.team)
end
# def can_copy_repository(repository)
# can_create_repository(repository.team)
# end
# def can_create_columns_in_repository(repository)
# is_normal_user_or_admin_of_team(repository.team)

View file

@ -36,6 +36,11 @@ Canaid::Permissions.register_for(Team) do
user.is_normal_user_or_admin_of_team?(team)
end
# create, copy, edit, destroy repository
can :manage_repository do |user, team|
user.is_admin_of_team?(team)
end
# create, import, edit, delete repository record
can :manage_repository_row do |user, team|
user.is_normal_user_or_admin_of_team?(team)

View file

@ -34,24 +34,22 @@
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="true"
<%= "disabled='disabled'" if !can_edit_and_destroy_repository repository and !can_copy_repository repository %>>
<%= "disabled='disabled'" unless can_manage_repository?(repository.team) %>>
<span class="glyphicon glyphicon-cog"></span>
<span class="caret"></span>
</div>
<% if can_edit_and_destroy_repository repository or can_copy_repository repository %>
<% if can_manage_repository?(repository.team) %>
<ul class="dropdown-menu pull-right">
<li class="dropdown-header">
<%= t("repositories.index.options_dropdown.header") %>
</li>
<% if can_edit_and_destroy_repository repository %>
<li>
<%= link_to t('repositories.index.options_dropdown.rename'),
team_repository_rename_modal_path(repository_id: repository),
class: "rename-repo-option",
remote: true %>
</li>
<% end %>
<% if can_copy_repository(repository) %>
<li>
<%= link_to t('repositories.index.options_dropdown.rename'),
team_repository_rename_modal_path(repository_id: repository),
class: "rename-repo-option",
remote: true %>
</li>
<% if repository.team.repositories.count < Constants::REPOSITORIES_LIMIT %>
<li>
<%= link_to t('repositories.index.options_dropdown.copy'),
team_repository_copy_modal_path(repository_id: repository),
@ -59,15 +57,13 @@
remote: true %>
</li>
<% end %>
<% if can_edit_and_destroy_repository repository %>
<li role="separator" class="divider"></li>
<li>
<%= link_to t('repositories.index.modal_delete.delete'),
team_repository_destroy_modal_path(repository_id: repository),
class: "delete-repo-option",
remote: true %>
</li>
<% end %>
<li role="separator" class="divider"></li>
<li>
<%= link_to t('repositories.index.modal_delete.delete'),
team_repository_destroy_modal_path(repository_id: repository),
class: "delete-repo-option",
remote: true %>
</li>
</ul>
<% end %>
</div>

View file

@ -19,11 +19,11 @@
<!-- Add new repository tab -->
<li role="presentation"
<% unless can_create_repository(current_team) %>
<% unless can_manage_repository?(current_team) || current_team.repositories.count < Constants::REPOSITORIES_LIMIT %>
class="disabled"
<% end %>>
<a
<% if can_create_repository(current_team) %>
<% if can_manage_repository?(current_team) && current_team.repositories.count < Constants::REPOSITORIES_LIMIT %>
href="<%= create_modal_team_repositories_path %>"
class='create-repository'
data-remote='true'