Created
October 23, 2019 07:46
-
-
Save stp-che/5e064b5112442224b9dd0d9d49e488d4 to your computer and use it in GitHub Desktop.
Statements permissions
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
class Statement < ApplicationRecord | |
PERMISSIONS = { | |
K_HIRE = { | |
create: Access::P_HIRE_ST_CREATE, | |
view: Access::P_HIRE_ST_VIEW, | |
process: Access::P_HIRE_ST_PROCESS | |
}, | |
K_DISMISS = { | |
create: Access::P_DISMISS_ST_CREATE, | |
view: Access::P_DISMISS_ST_VIEW, | |
process: Access::P_DISMISS_ST_PROCESS | |
}, | |
K_MOVE = { | |
create: Access::P_MOVE_ST_CREATE, | |
view: Access::P_MOVE_ST_VIEW, | |
process: Access::P_MOVE_ST_PROCESS | |
} | |
}.freeze | |
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
# StatementsController | |
def show | |
@user_permission.include?(Statement::PERMISSIONS[@statement.kind][:view]) | |
end | |
def permission_for_create | |
access_name = Statement::PERMISSIONS[params[:kind] || params[:statement][:kind]][:create] | |
if CurrentSession.context_by_permission(access_name).empty? | |
forbid! | |
end | |
end | |
# StatementsHelper | |
def can_process_statement? | |
access_name = Statement::PERMISSIONS[@statement.kind][:process] | |
CurrentSession.context_by_permission(access_name).present? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment