-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seperate pundit policies for "normal" use and admin use
They were getting too confusing and it was mixing up unrelated concerns too much before.
- Loading branch information
Showing
23 changed files
with
325 additions
and
193 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,35 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class AlertPolicy < ApplicationPolicy | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
def index? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def show? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def update? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def destroy? | ||
user.has_role?(:admin) | ||
end | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
sig { returns(ActiveRecord::Relation) } | ||
def resolve | ||
user.has_role?(:admin) ? scope.all : scope.none | ||
end | ||
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,35 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class ApiKeyPolicy < ApplicationPolicy | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
def index? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def show? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def update? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def create? | ||
user.has_role?(:admin) | ||
end | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
sig { returns(ActiveRecord::Relation) } | ||
def resolve | ||
user.has_role?(:admin) ? scope.all : scope.none | ||
end | ||
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,13 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class ApiUsagesPolicy < ApplicationPolicy | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
def index? | ||
user.has_role?(:admin) | ||
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,30 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class ApplicationsPolicy < ApplicationPolicy | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
def index? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def show? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def destroy? | ||
user.has_role?(:admin) | ||
end | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
sig { returns(ActiveRecord::Relation) } | ||
def resolve | ||
user.has_role?(:admin) ? scope.all : scope.none | ||
end | ||
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,40 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class AuthorityPolicy < ApplicationPolicy | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
def create? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def index? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def show? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def update? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def import? | ||
user.has_role?(:admin) | ||
end | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
sig { returns(ActiveRecord::Relation) } | ||
def resolve | ||
user.has_role?(:admin) ? scope.all : scope.none | ||
end | ||
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,13 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class BackgroundJobsPolicy < ApplicationPolicy | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
def index? | ||
user.has_role?(:admin) | ||
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,35 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class CommentPolicy < ApplicationPolicy | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
def index? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def show? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def update? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def resend? | ||
user.has_role?(:admin) | ||
end | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
sig { returns(ActiveRecord::Relation) } | ||
def resolve | ||
user.has_role?(:admin) ? scope.all : scope.none | ||
end | ||
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,30 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class ReportPolicy < ApplicationPolicy | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
def index? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def show? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def destroy? | ||
user.has_role?(:admin) | ||
end | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
sig { returns(ActiveRecord::Relation) } | ||
def resolve | ||
user.has_role?(:admin) ? scope.all : scope.none | ||
end | ||
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,25 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class RolePolicy < ApplicationPolicy | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
def index? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def show? | ||
user.has_role?(:admin) | ||
end | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
sig { returns(ActiveRecord::Relation) } | ||
def resolve | ||
user.has_role?(:admin) ? scope.all : scope.none | ||
end | ||
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,18 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class TestEmailsPolicy < ApplicationPolicy | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
def index? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def create? | ||
user.has_role?(:admin) | ||
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,36 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module Admin | ||
class UserPolicy < ApplicationPolicy | ||
extend T::Sig | ||
|
||
# TODO: Extract this into a DefaultAdminPolicy | ||
sig { returns(T::Boolean) } | ||
def index? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def show? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def update? | ||
user.has_role?(:admin) | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def destroy? | ||
user.has_role?(:admin) | ||
end | ||
|
||
class Scope < ApplicationPolicy::Scope | ||
sig { returns(ActiveRecord::Relation) } | ||
def resolve | ||
user.has_role?(:admin) ? scope.all : scope.none | ||
end | ||
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
Oops, something went wrong.