Class: Authorization::DevelopmentSupport::ChangeSupporter::AssignPrivilegeToRoleAction

Inherits:
AbstractAction
  • Object
show all
Defined in:
lib/declarative_authorization/development_support/change_supporter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractAction

#eql?, #hash, #inspect, readable_info, #resembles?, #resembles_any?, #weight

Constructor Details

#initialize(privilege_sym, context, role_sym) ⇒ AssignPrivilegeToRoleAction

Returns a new instance of AssignPrivilegeToRoleAction.



287
288
289
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 287

def initialize (privilege_sym, context, role_sym)
  @privilege, @context, @role = privilege_sym, context, role_sym
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



286
287
288
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 286

def context
  @context
end

#privilegeObject (readonly)

Returns the value of attribute privilege.



286
287
288
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 286

def privilege
  @privilege
end

#roleObject (readonly)

Returns the value of attribute role.



286
287
288
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 286

def role
  @role
end

Class Method Details

.specific_actions(candidate) ⇒ Object



272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 272

def self.specific_actions (candidate)
  privilege = AnalyzerEngine::Privilege.for_sym(
      candidate.failed_tests.first.privilege, candidate.engine)
  context = candidate.failed_tests.first.context
  user = candidate.failed_tests.first.user
  ([privilege] + privilege.ancestors).collect do |ancestor_privilege|
    user.role_symbols.collect {|role_sym| AnalyzerEngine::Role.for_sym(role_sym, candidate.engine) }.
        collect {|role| [role] + role.ancestors}.flatten.uniq.collect do |role|
      # apply checks later if privilege is already present in that role
      new(ancestor_privilege.to_sym, context, role.to_sym)
    end
  end.flatten
end

Instance Method Details

#apply(candidate) ⇒ Object



291
292
293
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 291

def apply (candidate)
  AnalyzerEngine.apply_change(candidate.engine, to_a)
end

#reverse?(other) ⇒ Boolean

Returns:

  • (Boolean)


295
296
297
298
299
300
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 295

def reverse? (other)
  other.is_a?(RemovePrivilegeFromRoleAction) and
      other.privilege == @privilege and
      other.context == @context and
      other.role == @role
end

#to_aObject



302
303
304
# File 'lib/declarative_authorization/development_support/change_supporter.rb', line 302

def to_a
  [:add_privilege, @privilege, @context, @role]
end