Skip to content

Commit

Permalink
Cleanup model checks
Browse files Browse the repository at this point in the history
  • Loading branch information
stage-rl committed Dec 4, 2023
1 parent 4cc123a commit 186746e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
11 changes: 0 additions & 11 deletions app/models/group_membership.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,4 @@ class GroupMembership < ApplicationRecord

belongs_to :group
belongs_to :user

before_destroy :validate_self_admin_removal, prepend: true

private

def validate_self_admin_removal
return unless group.type == 'AdminGroup' && user == Current.user

errors.add :base, "Administrátor nemôže odobrať administrátorské práva sám sebe"
throw :abort
end
end
8 changes: 2 additions & 6 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class User < ApplicationRecord
validates_presence_of :name, :email
validates_uniqueness_of :name, :email, scope: :tenant_id, case_sensitive: false

before_destroy :before_destroy, prepend: true
before_destroy :delete_user_group, prepend: true
after_create :handle_default_groups

def site_admin?
Expand All @@ -41,11 +41,7 @@ def user_group

private

def before_destroy
if self == Current.user
errors.add :name, "Administrátor nemôže zmazať sám seba"
throw :abort
end
def delete_user_group
user_group.destroy
end

Expand Down

0 comments on commit 186746e

Please sign in to comment.