Commit 1b7079e0 authored by hellekin's avatar hellekin

More policy specs

parent 95c5ab3c
# frozen_string_literal: true # frozen_string_literal: true
class AddressPolicy < ApplicationPolicy class AddressPolicy < ApplicationPolicy
class Scope < Scope def index?
def resolve user.maintainer?
scope.all end
end
def show?
true
end end
end end
...@@ -9,18 +9,6 @@ class AgentPolicy < ApplicationPolicy ...@@ -9,18 +9,6 @@ class AgentPolicy < ApplicationPolicy
record == user.agent || record_public? record == user.agent || record_public?
end end
def create?
user.editor?
end
def update?
create?
end
def destroy?
user.maintainer?
end
class Scope < Scope class Scope < Scope
def resolve def resolve
if user.current_agent_is_incommon? || user.leader? || user.maintainer? if user.current_agent_is_incommon? || user.leader? || user.maintainer?
......
...@@ -17,7 +17,7 @@ class ApplicationPolicy ...@@ -17,7 +17,7 @@ class ApplicationPolicy
end end
def create? def create?
false user.editor?
end end
# We don't have #new in API mode # We don't have #new in API mode
...@@ -26,7 +26,7 @@ class ApplicationPolicy ...@@ -26,7 +26,7 @@ class ApplicationPolicy
end end
def update? def update?
false create?
end end
# We don't have #edit in API mode # We don't have #edit in API mode
...@@ -35,7 +35,7 @@ class ApplicationPolicy ...@@ -35,7 +35,7 @@ class ApplicationPolicy
end end
def destroy? def destroy?
false user.maintainer?
end end
class Scope class Scope
......
# frozen_string_literal: true # frozen_string_literal: true
class CategoryPolicy < ApplicationPolicy class CategoryPolicy < TaxonomyPolicy
class Scope < Scope
def resolve
scope.all
end
end
end end
...@@ -9,18 +9,6 @@ class CollectionPolicy < ApplicationPolicy ...@@ -9,18 +9,6 @@ class CollectionPolicy < ApplicationPolicy
true true
end end
def create?
user.editor?
end
def update?
create?
end
def destroy?
user.maintainer?
end
class Scope < Scope class Scope < Scope
def resolve def resolve
scope.all scope.all
......
...@@ -20,14 +20,11 @@ class CorsOriginsPolicy ...@@ -20,14 +20,11 @@ class CorsOriginsPolicy
end end
def create? def create?
user.admin? user.maintainer?
end end
alias update? create?
def update? def destroy?
user.admin? user.maintainer?
end
def delete?
user.admin?
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
class EmailPolicy < ApplicationPolicy class EmailPolicy < ApplicationPolicy
class Scope < Scope def index?
def resolve user.leader? || user.maintainer?
scope.all end
end
def show?
true
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
class LinkPolicy < ApplicationPolicy class LinkPolicy < ApplicationPolicy
class Scope < Scope def index
def resolve true
scope.all end
end
def show
true
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
class LocationPolicy < ApplicationPolicy class LocationPolicy < ApplicationPolicy
class Scope < Scope def index?
def resolve user.maintainer?
scope.all end
end
def show?
true
end end
end end
...@@ -8,10 +8,4 @@ class MapPolicy < ApplicationPolicy ...@@ -8,10 +8,4 @@ class MapPolicy < ApplicationPolicy
def show? def show?
record_public? record_public?
end end
class Scope < Scope
def resolve
scope.all
end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
class NilClassPolicy < ApplicationPolicy class NilClassPolicy < ApplicationPolicy
def show?
false # Nobody can see anything
end
class Scope < Scope class Scope < Scope
def resolve def resolve
raise Pundit::NotDefinedError, 'Cannot scope NilClass' raise Pundit::NotDefinedError, 'Cannot scope NilClass'
end end
end end
def show?
true # false # Nobody can see nothing
end
end end
# frozen_string_literal: true # frozen_string_literal: true
class PhonePolicy < ApplicationPolicy class PhonePolicy < ApplicationPolicy
class Scope < Scope def index?
def resolve user.maintainer?
scope.all end
end
def show?
true
end end
end end
...@@ -8,22 +8,4 @@ class PositionPolicy < ApplicationPolicy ...@@ -8,22 +8,4 @@ class PositionPolicy < ApplicationPolicy
def show? def show?
true true
end end
def create?
user.editor?
end
def update?
create?
end
def destroy?
user.maintainer?
end
class Scope < Scope
def resolve
scope.all
end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
class ResourceAddressPolicy < ApplicationPolicy class ResourceAddressPolicy < AddressPolicy
class Scope < Scope
def resolve
scope.all
end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
class ResourceCollectionPolicy < ApplicationPolicy class ResourceCollectionPolicy < CollectionPolicy
class Scope < Scope
def resolve
scope.all
end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
class ResourceEmailPolicy < ApplicationPolicy class ResourceEmailPolicy < EmailPolicy
class Scope < Scope
def resolve
scope.all
end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
class ResourceLinkPolicy < ApplicationPolicy class ResourceLinkPolicy < LinkPolicy
class Scope < Scope
def resolve
scope.all
end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
class ResourcePhonePolicy < ApplicationPolicy class ResourcePhonePolicy < PhonePolicy
class Scope < Scope
def resolve
scope.all
end
end
end end
...@@ -9,18 +9,6 @@ class ResourcePolicy < ApplicationPolicy ...@@ -9,18 +9,6 @@ class ResourcePolicy < ApplicationPolicy
record_public? record_public?
end end
def create?
user.editor?
end
def update?
create?
end
def destroy?
user.maintainer?
end
class Scope < Scope class Scope < Scope
def resolve def resolve
if user.authenticated? == true if user.authenticated? == true
......
# frozen_string_literal: true # frozen_string_literal: true
class RolePolicy < ApplicationPolicy class RolePolicy < ApplicationPolicy
class Scope < Scope def index?
def resolve user.leader?
scope.all end
end
def show?
true
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
class SectionPolicy < ApplicationPolicy class SectionPolicy < TaxonomyPolicy
class Scope < Scope
def resolve
scope.all
end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
class TaxonomyPolicy < ApplicationPolicy class TaxonomyPolicy < ApplicationPolicy
class Scope < Scope def index?
def resolve true
scope.all end
end
def show?
true
end end
end end
# frozen_string_literal: true # frozen_string_literal: true
class UserEmailPolicy < ApplicationPolicy class UserEmailPolicy < EmailPolicy
class Scope < Scope
def resolve
scope.all
end
end
end end
...@@ -5,23 +5,11 @@ RSpec.describe AddressPolicy do ...@@ -5,23 +5,11 @@ RSpec.describe AddressPolicy do
subject { described_class } subject { described_class }
permissions ".scope" do permissions :index? do
pending "add some examples to (or delete) #{__FILE__}" pending 'is allowed to maintainer'
end end
permissions :show? do permissions :show? do
pending "add some examples to (or delete) #{__FILE__}" pending 'is always allowed'
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
end end
end end
...@@ -6,22 +6,18 @@ RSpec.describe AgentPolicy do ...@@ -6,22 +6,18 @@ RSpec.describe AgentPolicy do
subject { described_class } subject { described_class }
permissions ".scope" do permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}" pending 'resolves to all if current agent is IN COMMON'
pending 'resolves to all for leader'
pending 'resolves to all for maintainer'
pending 'resolves to visible records otherwise'
end end
permissions :show? do permissions :index? do
pending "add some examples to (or delete) #{__FILE__}" pending 'is always allowed'
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end end
permissions :update? do permissions :show? do
pending "add some examples to (or delete) #{__FILE__}" pending 'is allowed if user belongs to agent'
end pending 'is allowed if record is public'
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
end end
end end
require 'rails_helper'
RSpec.describe ApplicationPolicy do
let(:user) { User.new }
subject { described_class }
permissions '.scope' do
pending 'resolves to all'
end
permissions :index? do
pending 'is not allowed'
end
permissions :show? do
pending 'is not allowed'
end
permissions :create? do
pending 'is allowed to editor'
end
permissions :new? do
pending 'is never allowed'
end
permissions :update? do
pending 'follows create policy'
end
permissions :edit? do
pending 'is never allowed'
end
permissions :destroy? do
pending 'is allowed to maintainer'
end
end
require 'rails_helper' require 'rails_helper'
RSpec.describe CategoryPolicy do RSpec.describe CategoryPolicy do
let(:user) { User.new }
subject { described_class } subject { described_class }
permissions ".scope" do it 'follows TaxonomyPolicy' do
pending "add some examples to (or delete) #{__FILE__}" expect(subject.ancestors[1]).to eql(TaxonomyPolicy)
end
permissions :show? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
end end
end end
...@@ -6,22 +6,14 @@ RSpec.describe CollectionPolicy do ...@@ -6,22 +6,14 @@ RSpec.describe CollectionPolicy do
subject { described_class } subject { described_class }
permissions ".scope" do permissions ".scope" do
pending "add some examples to (or delete) #{__FILE__}" pending 'resolves to all'
end end
permissions :show? do permissions :index? do
pending "add some examples to (or delete) #{__FILE__}" pending "is always allowed"
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end end
permissions :update? do permissions :show? do
pending "add some examples to (or delete) #{__FILE__}" pending 'is always allowed'
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
end end
end end
require 'rails_helper'
RSpec.describe CorsOriginsPolicy do
let(:user) { User.new }
subject { described_class }
permissions :index? do
it 'is always allowed'
end
permissions :show? do
it 'is always allowed'
pending 'is only allowed for actual Agent\'s origins'
end
permissions :create? do
pending 'is allowed to maintainer'
end
permissions :update? do
pending 'follows create?'
end
permissions :destroy? do
pending 'follows create?'
end
end
...@@ -5,23 +5,13 @@ RSpec.describe EmailPolicy do ...@@ -5,23 +5,13 @@ RSpec.describe EmailPolicy do
subject { described_class } subject { described_class }
permissions ".scope" do permissions :index? do
pending "add some examples to (or delete) #{__FILE__}" pending 'is allowed for leader'
pending 'is allowed for maintainer'
pending 'is not allowed otherwise'
end end
permissions :show? do permissions :show? do
pending "add some examples to (or delete) #{__FILE__}" pending 'is always allowed'
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
end end
end end
...@@ -5,23 +5,11 @@ RSpec.describe LinkPolicy do ...@@ -5,23 +5,11 @@ RSpec.describe LinkPolicy do
subject { described_class } subject { described_class }
permissions ".scope" do permissions :index? do
pending "add some examples to (or delete) #{__FILE__}" pending 'is always allowed'
end end
permissions :show? do permissions :show? do
pending "add some examples to (or delete) #{__FILE__}" pending 'is always allowed'
end
permissions :create? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :update? do
pending "add some examples to (or delete) #{__FILE__}"
end
permissions :destroy? do
pending "add some examples to (or delete) #{__FILE__}"
end end
end end
...@@ -5,23 +5,11 @@ RSpec.describe LocationPolicy do ...@@ -5,23 +5,11 @@ RSpec.describe LocationPolicy do
subject { described_class } subject { described_class }
permissions ".scope" do permissions :index? do
pending "add some examples to (or delete) #{__FILE__}" pending 'can be listed by maintainers'
end end
permissions :show? do permissions :show? do
pending "add some examples to (or delete) #{__FILE__}" pending 'is always allowed'