Initial Commit
Co-authored-by: Subin <subinthattaparambil@gmail.com> Co-authored-by: Manoj <manojmj92@gmail.com> Co-authored-by: Nithin <webofnithin@gmail.com>
This commit is contained in:
53
app/policies/application_policy.rb
Normal file
53
app/policies/application_policy.rb
Normal file
@@ -0,0 +1,53 @@
|
||||
class ApplicationPolicy
|
||||
attr_reader :user, :record
|
||||
|
||||
def initialize(user, record)
|
||||
@user = user
|
||||
@record = record
|
||||
end
|
||||
|
||||
def index?
|
||||
false
|
||||
end
|
||||
|
||||
def show?
|
||||
scope.where(:id => record.id).exists?
|
||||
end
|
||||
|
||||
def create?
|
||||
false
|
||||
end
|
||||
|
||||
def new?
|
||||
create?
|
||||
end
|
||||
|
||||
def update?
|
||||
false
|
||||
end
|
||||
|
||||
def edit?
|
||||
update?
|
||||
end
|
||||
|
||||
def destroy?
|
||||
false
|
||||
end
|
||||
|
||||
def scope
|
||||
Pundit.policy_scope!(user, record.class)
|
||||
end
|
||||
|
||||
class Scope
|
||||
attr_reader :user, :scope
|
||||
|
||||
def initialize(user, scope)
|
||||
@user = user
|
||||
@scope = scope
|
||||
end
|
||||
|
||||
def resolve
|
||||
scope
|
||||
end
|
||||
end
|
||||
end
|
||||
18
app/policies/contact_policy.rb
Normal file
18
app/policies/contact_policy.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class ContactPolicy < ApplicationPolicy
|
||||
|
||||
def index?
|
||||
@user.administrator?
|
||||
end
|
||||
|
||||
def update?
|
||||
@user.administrator?
|
||||
end
|
||||
|
||||
def show?
|
||||
@user.administrator?
|
||||
end
|
||||
|
||||
def create?
|
||||
true
|
||||
end
|
||||
end
|
||||
26
app/policies/inbox_policy.rb
Normal file
26
app/policies/inbox_policy.rb
Normal file
@@ -0,0 +1,26 @@
|
||||
class InboxPolicy < ApplicationPolicy
|
||||
class Scope
|
||||
attr_reader :user, :scope
|
||||
|
||||
def initialize(user, scope)
|
||||
@user = user
|
||||
@scope = scope
|
||||
end
|
||||
|
||||
def resolve
|
||||
if user.administrator?
|
||||
scope.all
|
||||
elsif user.agent?
|
||||
user.assigned_inboxes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def index?
|
||||
true
|
||||
end
|
||||
|
||||
def destroy?
|
||||
@user.administrator?
|
||||
end
|
||||
end
|
||||
18
app/policies/user_policy.rb
Normal file
18
app/policies/user_policy.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
class UserPolicy < ApplicationPolicy
|
||||
|
||||
def index?
|
||||
true
|
||||
end
|
||||
|
||||
def create?
|
||||
@user.administrator?
|
||||
end
|
||||
|
||||
def update?
|
||||
@user.administrator?
|
||||
end
|
||||
|
||||
def destroy?
|
||||
@user.administrator?
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user