# Module Authority

- app/roles/authority.rb

Methods

A
  - add_access,
  - allow_read_for?
D
  - dev_access_for?
G
  - guest_access_for?
M
  - master_access_for?
R
  - report_access_for?,
  - repository_masters,
  - repository_readers,
  - repository_writers,
  - reset_access

Instance Public methods
add_access(user, *access) Link

Compatible with all access rights Should be rewrited for new access rights

Source: show

    # File app/roles/authority.rb, line 4
    def add_access(user, *access)
      access = if access.include?(:admin)
                 { project_access: UsersProject::MASTER }
               elsif access.include?(:write)
                 { project_access: UsersProject::DEVELOPER }
               else
                 { project_access: UsersProject::REPORTER }
               end
      opts = { user: user }
      opts.merge!(access)
      users_projects.create(opts)
    end

allow_read_for?(user) Link

Source: show

    # File app/roles/authority.rb, line 39
    def allow_read_for?(user)
      !users_projects.where(user_id: user.id).empty?
    end

dev_access_for?(user) Link

Source: show

    # File app/roles/authority.rb, line 51
    def dev_access_for?(user)
      !users_projects.where(user_id: user.id, project_access: [UsersProject::DEVELOPER, UsersProject::MASTER]).empty?
    end

guest_access_for?(user) Link

Source: show

    # File app/roles/authority.rb, line 43
    def guest_access_for?(user)
      !users_projects.where(user_id: user.id).empty?
    end

master_access_for?(user) Link

Source: show

    # File app/roles/authority.rb, line 55
    def master_access_for?(user)
      !users_projects.where(user_id: user.id, project_access: [UsersProject::MASTER]).empty?
    end

report_access_for?(user) Link

Source: show

    # File app/roles/authority.rb, line 47
    def report_access_for?(user)
      !users_projects.where(user_id: user.id, project_access: [UsersProject::REPORTER, UsersProject::DEVELOPER, UsersProject::MASTER]).empty?
    end

repository_masters() Link

Source: show

    # File app/roles/authority.rb, line 33
    def repository_masters
      keys = Key.joins({user: :users_projects}).
        where("users_projects.project_id = ? AND users_projects.project_access = ?", id, UsersProject::MASTER)
      keys.map(&:identifier)
    end

repository_readers() Link

Source: show

    # File app/roles/authority.rb, line 21
    def repository_readers
      keys = Key.joins({user: :users_projects}).
        where("users_projects.project_id = ? AND users_projects.project_access = ?", id, UsersProject::REPORTER)
      keys.map(&:identifier) + deploy_keys.map(&:identifier)
    end

repository_writers() Link

Source: show

    # File app/roles/authority.rb, line 27
    def repository_writers
      keys = Key.joins({user: :users_projects}).
        where("users_projects.project_id = ? AND users_projects.project_access = ?", id, UsersProject::DEVELOPER)
      keys.map(&:identifier)
    end

reset_access(user) Link

Source: show

    # File app/roles/authority.rb, line 17
    def reset_access(user)
      users_projects.where(project_id: self.id, user_id: user.id).destroy if self.id
    end