-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #221 from solver-it-sro/GO-401/deny_self_user_dele…
…tion
- Loading branch information
Showing
10 changed files
with
59 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 5 additions & 3 deletions
8
app/components/admin/groups/members_list_row_component.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<div class="w-16 h-16 justify-center items-center flex"> | ||
<img class="w-16 h-16 rounded-full" src="https://via.placeholder.com/64x64" /> | ||
<img class="w-16 h-16 rounded-full" src="https://via.placeholder.com/64x64"> | ||
</div> | ||
<div class="grow shrink basis-0 flex-col justify-start items-start gap-1 inline-flex"> | ||
<div class="text-center text-gray-900 text-lg font-medium leading-loose"><%= @user.name %></div> | ||
<div class="text-center text-gray-500 text-base font-normal leading-normal"><%= @user.email %></div> | ||
</div> | ||
<%= button_to admin_tenant_group_group_membership_path(Current.tenant, @group_membership.group, @group_membership), method: :delete do %> | ||
<%= render Common::DeleteButtonComponent.new %> | ||
<% if Pundit.policy(Current.user, [:admin, @group_membership]).destroy? %> | ||
<%= button_to admin_tenant_group_group_membership_path(Current.tenant, @group_membership.group, @group_membership), method: :delete do %> | ||
<%= render Common::DeleteButtonComponent.new %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
class Admin::UserPolicy < ApplicationPolicy | ||
attr_reader :user | ||
def initialize(actor, user_to_authorize) | ||
@actor = actor | ||
@user_to_authorize = user_to_authorize | ||
end | ||
|
||
def initialize(user_logged_in, user_to_authorize) | ||
@user = user_logged_in | ||
def user | ||
@actor | ||
end | ||
|
||
class Scope < Scope | ||
def initialize(actor, scope) | ||
@actor = actor | ||
@scope = scope | ||
end | ||
|
||
def user | ||
@actor | ||
end | ||
|
||
def resolve | ||
if @user.site_admin? | ||
if @actor.site_admin? | ||
scope.all | ||
else | ||
scope.where(tenant_id: @user.tenant_id) | ||
scope.where(tenant_id: @actor.tenant_id) | ||
end | ||
end | ||
end | ||
|
||
def index? | ||
@user.site_admin? || @user.admin? | ||
@actor.site_admin? || @actor.admin? | ||
end | ||
|
||
def show? | ||
@user.site_admin? || @user.admin? | ||
@actor.site_admin? || @actor.admin? | ||
end | ||
|
||
def create? | ||
@user.site_admin? || @user.admin? | ||
@actor.site_admin? || @actor.admin? | ||
end | ||
|
||
def new? | ||
create? | ||
end | ||
|
||
def update? | ||
@user.site_admin? || @user.admin? | ||
@actor.site_admin? || @actor.admin? | ||
end | ||
|
||
def edit? | ||
update? | ||
end | ||
|
||
def destroy? | ||
@user.site_admin? || @user.admin? | ||
end | ||
return false unless @actor.site_admin? || @actor.admin? | ||
return false if @user_to_authorize == @actor | ||
|
||
true | ||
end | ||
end |