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.
Move "validate_[activity]!" authorization into a module
Add Pundit Move "validate_chapter_leader!" and "validate_region_leader!" to Pundit classes.
- Loading branch information
1 parent
f263025
commit ee08e23
Showing
13 changed files
with
117 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module ControllerAuthorization | ||
def validate_admin! | ||
unless current_user.admin? | ||
flash[:error] = "You must be an Admin to see this page" | ||
redirect_to events_path | ||
end | ||
end | ||
|
||
def validate_organizer! | ||
@event ||= Event.find(params[:event_id]) | ||
if @event.historical? | ||
flash[:error] = "This feature is not available for historical events" | ||
return redirect_to events_path | ||
end | ||
|
||
unless @event.editable_by?(current_user) | ||
flash[:error] = "You must be an organizer for the event or an admin/chapter leader to see this page" | ||
redirect_to events_path | ||
end | ||
end | ||
|
||
def validate_checkiner! | ||
unless @event.checkiner?(current_user) || current_user.admin? | ||
flash[:error] = "You must be a checkiner, organizer, or admin to see this page." | ||
redirect_to events_path | ||
end | ||
end | ||
|
||
def validate_publisher! | ||
unless current_user.publisher? || current_user.admin? | ||
flash[:error] = "You must be authorized to publish events to see this page." | ||
redirect_to events_path | ||
end | ||
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class ApplicationPolicy | ||
attr_reader :user, :record | ||
|
||
def initialize(user, record) | ||
@user = user | ||
@record = 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class ChapterPolicy < ApplicationPolicy | ||
def new? | ||
user.admin? | ||
end | ||
|
||
def edit? | ||
record.has_leader?(user) | ||
end | ||
|
||
def update? | ||
record.has_leader?(user) | ||
end | ||
|
||
def create? | ||
user.admin? | ||
end | ||
|
||
def destroy? | ||
user.admin? | ||
end | ||
|
||
def modify_leadership? | ||
record.has_leader?(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class EventPolicy < ApplicationPolicy | ||
|
||
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,13 @@ | ||
class RegionPolicy < ApplicationPolicy | ||
def edit? | ||
record.has_leader?(user) | ||
end | ||
|
||
def update? | ||
record.has_leader?(user) | ||
end | ||
|
||
def modify_leadership? | ||
record.has_leader?(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