-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To keep up with on-going code improvement, I would like to propose an initial Pundit policy for BsRequest
- Loading branch information
Showing
2 changed files
with
18 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class BsRequestPolicy < ApplicationPolicy | ||
def initialize(user, record) | ||
raise Pundit::NotAuthorizedError, 'record does not exist' unless record | ||
@user = user | ||
@record = record | ||
end | ||
|
||
def create? | ||
# new request should not have an id (BsRequest#number) | ||
return false if @record.number | ||
# dont let user set approver other than himself unless he is admin | ||
![nil, @user.login].include?(@record.approver) && !@user.is_admin? ? false : true | ||
end | ||
end |