-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deny admin self deletion and self admin rights revocation #221
Conversation
app/models/user.rb
Outdated
def delete_user_group | ||
def before_destroy | ||
if self == Current.user | ||
errors.add :name, "Administrátor nemôže zmazať svojho používateľa" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tu chceme asi povedat, ze nemozes zmazat sam seba a idealne by bolo aby ten button ani nebolo vidiet.
</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 %> | ||
<% unless @group_membership.group.type == "AdminGroup" && @group_membership.user == Current.user %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nemame na toto presne tie policy objekty ci ideme duplikovat logiku?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kedze tu chcem ten objekt sice vymenovat, len neumoznit mazanie, tak neviem ako tu pouzit policy. Takze ak, tak daj pls vediet ako, alebo posli priklad. Neukazat, ze tam ten admin je, mi pripada cudne
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ano, uz som si to aj ja nasiel. A spravil. A hned som mal na pozadi warning, ze urcite sa ti nebude pacit toto v komponente (lebo select do DB). Napriek tomu, ze pundit vyslovene vyzyva k pouzivaniu vo viewoch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To, kde sa vykona ten select je vecou toho ako sa tie objekty hore loadnu. Cize nemusi to nutne znamenat ziadny select navyse.
Príklad nemám ale logicky. Toto JE politika ako sa môže a nemôže mazať
group membership. To by sme mali mať v nejakej policy.
…On Thu, Nov 30, 2023, 20:48 Robo Lences ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In app/components/admin/groups/members_list_row_component.html.erb
<https://github.com/solver-it-sro/govbox-pro/pull/221#discussion_r1411188073>
:
> </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 %>
+<% unless @group_membership.group.type == "AdminGroup" && @group_membership.user == Current.user %>
Kedze tu chcem ten objekt sice vymenovat, len neumoznit mazanie, tak
neviem ako tu pouzit policy. Takze ak, tak daj pls vediet ako, alebo posli
priklad. Neukazat, ze tam ten admin je, mi pripada cudne
—
Reply to this email directly, view it on GitHub
<https://github.com/solver-it-sro/govbox-pro/pull/221#discussion_r1411188073>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAGNZWGRJQUTSYMZR4DTP3YHDPJNAVCNFSM6AAAAABABSIX7OVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTONJYGMZDIOJYG4>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
def destroy? | ||
@user.site_admin? || @user.admin? | ||
(@user.site_admin? || @user.admin?) && !(@group_membership.user == @user && @group_membership.group.type == 'AdminGroup') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Toto by som rozdelil aspon na dva riadky lebo sa to zle cita a su to vlastne rozne podmienky
nieco v zmysle:
return false if @group_membership.user == @user
return true if @user.site_admin? || @user.admin?
return true
imho by sam seba si nemal vediet zmazat vobec nikdy, nejako sa mi tam nepozdava to obmedzenie na admin group
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ale tak to je odobranie sa zo skupiny (nie zmazanie usera). A admin moze chciet napr nieco otestovat, hodi sa do skupiny, a nasledne sa z nej odoberie. Aktualne mi len podpisovanie napada.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ano myslel som tym clenstvo v skupine vseobecne. Ale pravda, ze undo by mal vediet asi spravit cize dava zmysel, aby zmazal aj sam seba pokial si neodpali admina.
app/policies/admin/user_policy.rb
Outdated
@@ -5,6 +5,7 @@ class Admin::UserPolicy < ApplicationPolicy | |||
|
|||
def initialize(user_logged_in, user_to_authorize) | |||
@user = user_logged_in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@actor
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nejako som to ponastavoval, ale pozri, ci si s tym takto OK. Vyrabam tam natvrdo metodu user
, kedze Pundit celkom vyzera, ze s nou pocita (vsade je tam attr_reader :user
). Aj ked aj bez nej mi to islo. Trochu sa bojim takychto zasahov mimo zdokumentovanych standardov
app/policies/admin/user_policy.rb
Outdated
@@ -42,7 +43,6 @@ def edit? | |||
end | |||
|
|||
def destroy? | |||
@user.site_admin? || @user.admin? | |||
(@user.site_admin? || @user.admin?) && @user_to_authorize != @user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Toto tiez rozdelme na riadky.
app/policies/admin/user_policy.rb
Outdated
@user.site_admin? || @user.admin? | ||
end | ||
return false unless @actor.site_admin? || @actor.admin? | ||
return true unless @user_to_authorize != @actor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mas tu dva zapory.
return true unless @user_to_authorize != @actor | |
return false if @user_to_authorize == @actor |
app/models/group_membership.rb
Outdated
private | ||
|
||
def validate_self_admin_removal | ||
return unless group.type == 'AdminGroup' && user == Current.user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Toto tu je este potrebne? Resp vidim tu este duplicitu
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beriem teda, ze hovoris, ze princip je chytat taketo chyby co najvyssie, a neduplikovat to "dole". Tak?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kedze pouzivame pundit, ktory vytrhava security checky do samostatneho layer, tak to drzme teda tam.
app/models/user.rb
Outdated
has_many :message_drafts, foreign_key: :author_id | ||
has_many :automation_rules, class_name: 'Automation::Rule' | ||
has_many :filters, foreign_key: :author_id | ||
|
||
validates_presence_of :name, :email | ||
validates_uniqueness_of :name, :email, scope: :tenant_id, case_sensitive: false | ||
|
||
before_destroy :delete_user_group, prepend: true | ||
before_destroy :before_destroy, prepend: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Toto bolo pekne pomenovane, ze co to urobi a teraz uz nevies co to urobi. Netreba sa hanbit mat aj 2 metody zavesene na before_destroy hook ak to dava zmysel
No description provided.