forked from XaoGao/rubywork_ru
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
361 additions
and
23 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
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,16 +1,14 @@ | ||
class ApplicationController < ActionController::Base | ||
before_action :configure_permitted_parameters, if: :devise_controller? | ||
|
||
rescue_from ActionPolicy::Unauthorized, with: :user_not_authorized | ||
rescue_from ActionPolicy::Unauthorized do |_e| | ||
redirect_to root_path | ||
end | ||
|
||
private | ||
|
||
def configure_permitted_parameters | ||
devise_parameter_sanitizer.permit(:sign_up, keys: %i[name avatar]) | ||
devise_parameter_sanitizer.permit(:account_update, keys: %i[name avatar]) | ||
end | ||
|
||
def user_not_authorized | ||
redirect_to root_path | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
# Base class for application policies | ||
class ApplicationPolicy < ActionPolicy::Base | ||
# Configure additional authorization contexts here | ||
# (`user` is added by default). | ||
# | ||
# authorize :account, optional: true | ||
# | ||
# Read more about authorization context: https://actionpolicy.evilmartians.io/#/authorization_context | ||
def allow_record | ||
current_admin? || owner_record? | ||
end | ||
|
||
# Define shared methods useful for most policies. | ||
# For example: | ||
# | ||
# def owner? | ||
# record.user_id == user.id | ||
# end | ||
private | ||
|
||
def current_admin? | ||
user.admin? | ||
end | ||
|
||
def owner_record? | ||
user.id == record.user_id | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class VacancyPolicy < ApplicationPolicy | ||
alias_rule :edit?, :destroy?, :update?, to: :manage? | ||
|
||
def manage? | ||
allowed_to?(:allow_record) | ||
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
Oops, something went wrong.