forked from railsbridge/bridge_troll
-
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.
Add a LocationPolicy to handle edit/archive permissions
Create a separate "archive" action rather than handling update and archive in the "update" action. This requires adding some JS magic to swap out the `action` of the Location form right when the user clicks it. It looks like <input type='submit' data-custom-action='beep/boop'>
- Loading branch information
1 parent
de2e2e4
commit 9a99904
Showing
6 changed files
with
42 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jQuery -> | ||
$('input[type=submit][data-custom-action]').click (e) -> | ||
$input = $(e.target) | ||
$input.closest('form').attr('action', $input.data('custom-action')) |
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,13 @@ | ||
class LocationPolicy < ApplicationPolicy | ||
def destroy? | ||
record.events.count == 0 | ||
end | ||
|
||
def archive? | ||
record.archivable_by?(user) | ||
end | ||
|
||
def edit? | ||
record.editable_by?(user) | ||
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