Class: Reactor::Permission::PermissionProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/reactor/permission.rb

Overview

This class acts as a proxy to underlying permission checking classes. There are three possible cases for each permission type (live, read, write, root, create_children):

  1. Given user is SuperUser - all permissions granted
  2. Given user has the permission
  3. Given user doesn't have the permission

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ PermissionProxy

Returns a new instance of PermissionProxy.

Signature:

  • nodoc:



117
118
119
120
121
# File 'lib/reactor/permission.rb', line 117

def initialize(obj) #:nodoc:
  @obj = obj
  @cache = Reactor::Cache::Permission.instance
  @lookup = PermissionLookup.new(obj)
end

Class Method Details

.permissionsObject

A table with all available permissions and their identifier.



240
241
242
243
244
245
246
247
248
# File 'lib/reactor/permission.rb', line 240

def self.permissions
  @permissions ||= {
    read: "permissionRead",
    root: "permissionRoot",
    live: "permissionLiveServerRead",
    write: "permissionWrite",
    create_children: "permissionCreateChildren"
  }
end

Instance Method Details

#clear(permission) ⇒ Object

Takes away the given permission from all groups currently set.



208
209
210
211
212
# File 'lib/reactor/permission.rb', line 208

def clear(permission)
  identifier = identifier(permission)

  crul_obj.permission_clear(identifier)
end

#create_children?(user = nil) ⇒ Boolean

Returns true if given user (or current user, if none given) has 'create_children' permission

Returns:

  • (Boolean)


144
145
146
# File 'lib/reactor/permission.rb', line 144

def create_children?(user = nil)
  granted?(user, :root) || granted?(user, :create_children)
end

#delete?(user = nil) ⇒ Boolean

Returns:

  • (Boolean)

See Also:



149
150
151
# File 'lib/reactor/permission.rb', line 149

def delete?(user = nil)
  root?(user)
end

#edit?(user = nil) ⇒ Boolean

Returns:

  • (Boolean)

See Also:



164
165
166
# File 'lib/reactor/permission.rb', line 164

def edit?(user = nil)
  write?(user)
end

#grant(permission, groups) ⇒ Object

Grants the given groups the given permission, without effecting already existing groups.



191
192
193
194
195
196
# File 'lib/reactor/permission.rb', line 191

def grant(permission, groups)
  identifier = identifier(permission)

  groups = [groups] if groups.is_a?(::String)
  crul_obj.permission_grant(identifier, groups)
end

#live?(user = nil) ⇒ Boolean

Returns true if given user (or current user, if none given) has 'live' permission

Returns:

  • (Boolean)


124
125
126
# File 'lib/reactor/permission.rb', line 124

def live?(user = nil)
  granted?(user, :live)
end

#read?(user = nil) ⇒ Boolean

Returns true if given user (or current user, if none given) has 'read' permission

Returns:

  • (Boolean)


129
130
131
# File 'lib/reactor/permission.rb', line 129

def read?(user = nil)
  granted?(user, :root) || granted?(user, :read)
end

#release?(user = nil) ⇒ Boolean

Returns true if given user has permissions required to release an object (the exact permissions depend on the state of the object)

Returns:

  • (Boolean)


170
171
172
173
174
175
176
177
178
# File 'lib/reactor/permission.rb', line 170

def release?(user = nil)
  if !has_workflow?
    # NOTE: order matters for speed
    write?(user) || root?(user)
  else
    # this is slow
    root?(user) || (has_workflow_api? && obj.workflow.release?)
  end
end

#revert?(user = nil) ⇒ Boolean

Returns:

  • (Boolean)

See Also:



159
160
161
# File 'lib/reactor/permission.rb', line 159

def revert?(user = nil)
  write?(user)
end

#revoke(permission, groups) ⇒ Object

Takes away the given permission from the given groups, without effecting already existing groups.



200
201
202
203
204
205
# File 'lib/reactor/permission.rb', line 200

def revoke(permission, groups)
  identifier = identifier(permission)

  groups = [groups] if groups.is_a?(::String)
  crul_obj.permission_revoke(identifier, groups)
end

#root?(user = nil) ⇒ Boolean

Returns true if given user (or current user, if none given) has 'root' permission

Returns:

  • (Boolean)


139
140
141
# File 'lib/reactor/permission.rb', line 139

def root?(user = nil)
  granted?(user, :root)
end

#set(permission, groups) ⇒ Object

Setter to overwrite the current groups for the given permission with the given groups.



182
183
184
185
186
187
# File 'lib/reactor/permission.rb', line 182

def set(permission, groups)
  identifier = identifier(permission)

  groups = [groups] if groups.is_a?(::String)
  crul_obj.permission_set(identifier, groups)
end

#take?(user = nil) ⇒ Boolean

Returns:

  • (Boolean)

See Also:



154
155
156
# File 'lib/reactor/permission.rb', line 154

def take?(user = nil)
  write?(user)
end

#write?(user = nil) ⇒ Boolean

Returns true if given user (or current user, if none given) has 'write' permission

Returns:

  • (Boolean)


134
135
136
# File 'lib/reactor/permission.rb', line 134

def write?(user = nil)
  granted?(user, :root) || granted?(user, :write)
end