Sha256: f992594272b87e9d6efa857ee149cfe550eb50152152e8eb70f2e4fbf0902385

Contents?: true

Size: 659 Bytes

Versions: 13

Compression:

Stored size: 659 Bytes

Contents

module RocketJobMissionControl
  class Authorization
    ROLES = %i[admin editor operator manager dirmon user view].freeze
    attr_accessor *ROLES
    attr_accessor :login

    def initialize(roles: [], login: nil)
      @login = login
      return if roles.blank?

      invalid_roles = roles - ROLES
      raise(ArgumentError, "Invalid Roles Supplied: #{invalid_roles.inspect}") unless invalid_roles.empty?

      roles.each { |r| inherit_less_privilege_roles(r) }
    end

    def inherit_less_privilege_roles(role)
      index = ROLES.index(role)
      roles = ROLES[index..-1]
      roles.each { |role| public_send("#{role}=", true) }
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
rocketjob_mission_control-6.1.0 app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-6.0.7 app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-6.0.6 app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-6.0.5 app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-6.0.4 app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-6.0.3 app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-6.0.2 app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-6.0.1 app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-6.0.0 app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-6.0.0.beta app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-5.0.1 app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-5.0.0 app/models/rocket_job_mission_control/authorization.rb
rocketjob_mission_control-5.0.0.beta1 app/models/rocket_job_mission_control/authorization.rb