Skip to content

Commit

Permalink
bugfix: closes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahcssiqueira committed Oct 2, 2024
1 parent b51f388 commit ea03e6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UsersController < ApplicationController
before_action :set_user, only: [ :edit, :update ]
before_action :authorize_admin!, only: [ :edit, :update, :destroy ]
before_action :authorize_access!, only: [ :edit, :update, :destroy ]

def index
@user = User.all
Expand Down Expand Up @@ -57,6 +57,12 @@ def destroy
end
end

# Logic for authorization
def authorize_access!
unless current_user.admin? || current_user == @user
redirect_to root_path, alert: "You are not authorized to perform this action."
end
end

private

Expand Down
1 change: 1 addition & 0 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@
<% else %>
<p>Create account</p>
<% end %>
</div>

0 comments on commit ea03e6c

Please sign in to comment.