-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(recipes/pundit): configure for active admin
- Loading branch information
1 parent
0e481bc
commit 3a7a0dc
Showing
10 changed files
with
114 additions
and
19 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
lib/potassium/assets/active_admin/policies/admin_user_policy.rb
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,2 @@ | ||
class BackOffice::AdminUserPolicy < BackOffice::DefaultPolicy | ||
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,2 @@ | ||
class BackOffice::ActiveAdmin::CommentPolicy < BackOffice::DefaultPolicy | ||
end |
49 changes: 49 additions & 0 deletions
49
lib/potassium/assets/active_admin/policies/default_policy.rb
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,49 @@ | ||
class BackOffice::DefaultPolicy | ||
attr_reader :admin_user, :record | ||
|
||
def initialize(admin_user, record) | ||
@admin_user = admin_user | ||
@record = record | ||
end | ||
|
||
def index? | ||
true | ||
end | ||
|
||
def show? | ||
true | ||
end | ||
|
||
def create? | ||
true | ||
end | ||
|
||
def new? | ||
create? | ||
end | ||
|
||
def update? | ||
true | ||
end | ||
|
||
def edit? | ||
update? | ||
end | ||
|
||
def destroy? | ||
true | ||
end | ||
|
||
class Scope | ||
attr_reader :admin_user, :scope | ||
|
||
def initialize(admin_user, scope) | ||
@admin_user = admin_user | ||
@scope = scope | ||
end | ||
|
||
def resolve | ||
scope.all | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class BackOffice::ActiveAdmin::PagePolicy < BackOffice::DefaultPolicy | ||
end |
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe "Pundit" do | ||
before :all do | ||
drop_dummy_database | ||
remove_project_directory | ||
create_dummy_project("pundit" => true, "devise" => true, "admin" => true) | ||
end | ||
|
||
it "adds the Pundit gem to Gemfile" do | ||
content = IO.read("#{project_path}/Gemfile") | ||
|
||
expect(content).to include("gem 'pundit'") | ||
end | ||
|
||
it "setup active admin" do | ||
content = IO.read("#{project_path}/config/initializers/active_admin.rb") | ||
|
||
expect(content).to include("config.authorization_adapter = ActiveAdmin::PunditAdapter") | ||
expect(content).to include("config.pundit_default_policy = 'BackOffice::DefaultPolicy'") | ||
expect(content).to include("config.pundit_policy_namespace = :back_office") | ||
end | ||
|
||
it "creates default policy" do | ||
content = IO.read("#{project_path}/app/policies/back_office/default_policy.rb") | ||
|
||
expect(content).to include("class BackOffice::DefaultPolicy") | ||
end | ||
end |