Skip to content

Commit

Permalink
Merge pull request #220 from solver-it-sro/GO-246/site_admin_cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-rl authored Dec 4, 2023
2 parents 8592c14 + 6e9c3fd commit a467129
Show file tree
Hide file tree
Showing 33 changed files with 69 additions and 323 deletions.
33 changes: 0 additions & 33 deletions app/components/admin/tenants/tenant_form_component.html.erb

This file was deleted.

6 changes: 0 additions & 6 deletions app/components/admin/tenants/tenant_form_component.rb

This file was deleted.

15 changes: 0 additions & 15 deletions app/components/admin/tenants/tenants_list_component.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/components/admin/tenants/tenants_list_component.rb

This file was deleted.

18 changes: 0 additions & 18 deletions app/components/admin/tenants/tenants_list_row_component.html.erb

This file was deleted.

5 changes: 0 additions & 5 deletions app/components/admin/tenants/tenants_list_row_component.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<%= render Common::EditButtonComponent.new %>
<% end %>
<% if Pundit.policy(Current.user, [:admin, @user]).destroy? %>
<%= button_to admin_tenant_user_path(@user.tenant, [:admin, @user]), method: :delete do %>
<%= button_to admin_tenant_user_path(@user.tenant, @user), method: :delete do %>
<%= render Common::DeleteButtonComponent.new %>
<% end %>
<% end %>
Expand Down
64 changes: 0 additions & 64 deletions app/controllers/admin/tenants_controller.rb

This file was deleted.

2 changes: 0 additions & 2 deletions app/helpers/tenants_helper.rb

This file was deleted.

21 changes: 14 additions & 7 deletions app/lib/sidebar_menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ def initialize(controller, action, parameters = nil)
private

def initial_structure(controller, _action)
return admin_main_menu if (controller.in? %w[groups users tags tag_groups automation_rules boxes tenants
filters]) && (Current.user.admin? || Current.user.site_admin?)
return admin_menu + site_admin_menu if controller.in? %w[groups users tags tag_groups automation_rules boxes filters]

default_main_menu
end
Expand All @@ -26,22 +25,30 @@ def default_main_menu
]
end

def admin_main_menu
def admin_menu
return [] unless Current.user.admin?

[
Layout::BackToBoxComponent.new,
TW::SidebarMenuDividerComponent.new(name: 'Nastavenia'),
TW::SidebarMenuItemComponent.new(name: 'Filtre', url: filters_path, icon: Icons::BookmarkComponent.new),
TW::SidebarMenuItemComponent.new(name: 'Pravidlá', url: settings_automation_rules_path, icon: Icons::FunnelComponent.new),
TW::SidebarMenuDividerComponent.new(name: 'Administrácia'),
Current.user.site_admin? ? TW::SidebarMenuItemComponent.new(name: 'Tenanti', url: admin_tenants_path, icon: Icons::RectangleGroupComponent.new) : nil,
TW::SidebarMenuItemComponent.new(name: 'Používatelia', url: admin_tenant_users_path(Current.tenant), icon: Icons::UsersComponent.new),
TW::SidebarMenuItemComponent.new(name: 'Prístup', url: admin_tenant_tag_groups_path(Current.tenant), icon: Icons::LockClosedComponent.new),
TW::SidebarMenuItemComponent.new(name: 'Schránky', url: admin_tenant_boxes_path(Current.tenant), icon: Icons::RectangleStackComponent.new),
TW::SidebarMenuItemComponent.new(name: 'Skupiny', url: admin_tenant_groups_path(Current.tenant), icon: Icons::UserGroupsComponent.new),
TW::SidebarMenuItemComponent.new(name: 'Štítky', url: admin_tenant_tags_path(Current.tenant), icon: Icons::TagComponent.new),
TW::SidebarMenuItemComponent.new(name: 'Štítky', url: admin_tenant_tags_path(Current.tenant), icon: Icons::TagComponent.new)
]
end

def site_admin_menu
return [] unless Current.user.site_admin?

[
Layout::SidebarDividerComponent.new,
TW::SidebarMenuDividerComponent.new(name: 'Admin'),
TW::SidebarMenuItemComponent.new(name: 'Good Job Dashboard', url: good_job_path, icon: Icons::CogSixToothComponent.new),
].compact
TW::SidebarMenuItemComponent.new(name: 'Good Job Dashboard', url: good_job_path, icon: Icons::CogSixToothComponent.new)
]
end
end
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class User < ApplicationRecord

has_many :group_memberships, dependent: :destroy
has_many :groups, through: :group_memberships
has_many :own_tags, class_name: 'Tag', inverse_of: :owner, dependent: :nullify
has_many :own_tags, class_name: 'Tag', inverse_of: :owner, foreign_key: :owner_id, dependent: :nullify
has_many :message_drafts, foreign_key: :author_id
has_many :automation_rules, class_name: 'Automation::Rule'
has_many :filters, foreign_key: :author_id
Expand Down
9 changes: 6 additions & 3 deletions app/policies/admin/audit_log_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ def initialize(user, audit_log)

class Scope < Scope
def resolve
@user.site_admin? ? scope.all : scope.where(tenant: @user.tenant)
scope.where(tenant: @user.tenant)
end
end

def index?
Current.tenant.feature_enabled?(:audit_log) && (@user.site_admin? || @user.admin?)
return false unless Current.tenant.feature_enabled?(:audit_log)
return false unless @user.admin?

true
end

def scroll?
Current.tenant.feature_enabled?(:audit_log) && index?
index?
end
end
12 changes: 6 additions & 6 deletions app/policies/admin/box_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,35 @@ def initialize(user, box)

class Scope < Scope
def resolve
@user.site_admin? ? scope.all : scope.where(tenant: @user.tenant)
scope.where(tenant: @user.tenant)
end
end

def index
@user.site_admin? || @user.admin?
@user.admin?
end

def show?
@user.site_admin? || @user.admin?
@user.admin?
end

def create?
@user.site_admin? || @user.admin?
@user.admin?
end

def new?
create?
end

def update?
@user.site_admin? || @user.admin?
@user.admin?
end

def edit?
update?
end

def destroy?
@user.site_admin? || @user.admin?
@user.admin?
end
end
10 changes: 3 additions & 7 deletions app/policies/admin/group_membership_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,20 @@ def initialize(user, group_membership)

class Scope < Scope
def resolve
if @user.site_admin?
scope.all
else
scope.includes(:user, :group).where(user: { tenant_id: Current.tenant.id }, group: { tenant_id: Current.tenant.id })
end
scope.includes(:user, :group).where(user: { tenant: Current.tenant }, group: { tenant: Current.tenant })
end
end

def create?
return false unless @user.site_admin? || @user.admin?
return false unless @user.admin?
return false unless @group_membership.group.tenant == Current.tenant
return false unless @group_membership.user.tenant == Current.tenant

true
end

def destroy?
return false unless @user.site_admin? || @user.admin?
return false unless @user.admin?
return true unless @group_membership.user == @user && @group_membership.group.type == 'AdminGroup'

false
Expand Down
25 changes: 10 additions & 15 deletions app/policies/admin/group_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,20 @@ def initialize(user, group)

class Scope < Scope
def resolve
if @user.site_admin?
scope.all
else
scope.where(tenant_id: @user.tenant_id)
end
scope.where(tenant: @user.tenant)
end
end

def index?
@user.site_admin? || @user.admin?
@user.admin?
end

def show?
@user.site_admin? || @user.admin?
@user.admin?
end

def create?
@user.site_admin? || @user.admin?
@user.admin?
end

def new?
Expand All @@ -37,7 +33,7 @@ def new?
def update?
return false unless @group.editable?

@user.site_admin? || @user.admin?
@user.admin?
end

def edit?
Expand All @@ -49,25 +45,24 @@ def edit_members?
end

def show_members?
@user.site_admin? || @user.admin?
@user.admin?
end

def edit_permissions?
@user.site_admin? || @user.admin?
@user.admin?
end

def destroy?
return false if @group.system?

@user.site_admin? || @user.admin?
@user.admin?
end

def search_non_members?
@user.site_admin? || @user.admin?
@user.admin?
end

def search_non_tags?
@user.site_admin? || @user.admin?
@user.admin?
end

end
Loading

0 comments on commit a467129

Please sign in to comment.