Skip to content

Instantly share code, notes, and snippets.

@stp-che
Created October 23, 2019 07:46
Show Gist options
  • Save stp-che/5e064b5112442224b9dd0d9d49e488d4 to your computer and use it in GitHub Desktop.
Save stp-che/5e064b5112442224b9dd0d9d49e488d4 to your computer and use it in GitHub Desktop.
Statements permissions
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
# 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