# Module Account

- app/roles/account.rb

Methods

A
  - abilities,
  - authorized_groups,
  - authorized_projects
B
  - block
C
  - can?,
  - can_create_group?,
  - can_create_project?,
  - cared_merge_requests
F
  - first_name
I
  - identifier,
  - is_admin?
L
  - last_activity_project
M
  - my_own_projects
N
  - namespace_id,
  - namespaces
P
  - project_ids,
  - projects_limit_percent,
  - projects_sorted_by_activity
R
  - recent_push,
  - require_ssh_key?
S
  - several_namespaces?

Instance Public methods
abilities() Link

Source: show

    # File app/roles/account.rb, line 29
    def abilities
      @abilities ||= begin
                       abilities = Six.new
                       abilities << Ability
                       abilities
                     end
    end

authorized_groups() Link

Source: show

    # File app/roles/account.rb, line 109
    def authorized_groups
      @authorized_groups ||= begin
                             groups = Group.where(id: self.projects.pluck(:namespace_id)).all
                             groups = groups + self.groups
                             groups.uniq
                           end
    end

authorized_projects() Link

Source: show

    # File app/roles/account.rb, line 117
    def authorized_projects
      Project.authorized_for(self)
    end

block() Link

Remove user from all projects and set blocked attribute to true

Source: show

    # File app/roles/account.rb, line 59
    def block
      users_projects.find_each do |membership|
        return false unless membership.destroy
      end

      self.blocked = true
      save
    end

can?(action, subject) Link

Source: show

    # File app/roles/account.rb, line 37
    def can? action, subject
      abilities.allowed?(self, action, subject)
    end

can_create_group?() Link

Source: show

    # File app/roles/account.rb, line 25
    def can_create_group?
      is_admin?
    end

can_create_project?() Link

Source: show

    # File app/roles/account.rb, line 21
    def can_create_project?
      projects_limit > my_own_projects.count
    end

cared_merge_requests() Link

Source: show

    # File app/roles/account.rb, line 49
    def cared_merge_requests
      MergeRequest.where("author_id = :id or assignee_id = :id", id: self.id)
    end

first_name() Link

Source: show

    # File app/roles/account.rb, line 45
    def first_name
      name.split.first unless name.blank?
    end

identifier() Link

Returns a string for use as a Gitolite user identifier

Note that Gitolite 2.x requires the following pattern for users:

    ^@?[0-9a-zA-Z][0-9a-zA-Z._\@+-]*$

Source: show

    # File app/roles/account.rb, line 7
    def identifier
      # Replace non-word chars with underscores, then make sure it starts with
      # valid chars
      email.gsub(%r\W/, '_').gsub(%r\A([\W\_])+/, '')
    end

is_admin?() Link

Source: show

    # File app/roles/account.rb, line 13
    def is_admin?
      admin
    end

last_activity_project() Link

Source: show

    # File app/roles/account.rb, line 41
    def last_activity_project
      projects.first
    end

my_own_projects() Link

Source: show

    # File app/roles/account.rb, line 121
    def my_own_projects
      Project.personal(self)
    end

namespace_id() Link

Source: show

    # File app/roles/account.rb, line 105
    def namespace_id
      namespace.try :id
    end

namespaces() Link

Source: show

    # File app/roles/account.rb, line 86
    def namespaces
      namespaces = []

      # Add user account namespace
      namespaces << self.namespace if self.namespace

      # Add groups you can manage
      namespaces += if admin
                      Group.all
                    else
                      groups.all
                    end
      namespaces
    end

project_ids() Link

Source: show

    # File app/roles/account.rb, line 53
    def project_ids
      projects.map(&:id)
    end

projects_limit_percent() Link

Source: show

    # File app/roles/account.rb, line 68
    def projects_limit_percent
      return 100 if projects_limit.zero?
      (my_own_projects.count.to_f / projects_limit) * 100
    end

projects_sorted_by_activity() Link

Source: show

    # File app/roles/account.rb, line 82
    def projects_sorted_by_activity
      projects.sorted_by_activity
    end

recent_push(project_id = nil) Link

Source: show

    # File app/roles/account.rb, line 73
    def recent_push project_id = nil
      # Get push events not earlier than 2 hours ago
      events = recent_events.code_push.where("created_at > ?", Time.now - 2.hours)
      events = events.where(project_id: project_id) if project_id

      # Take only latest one
      events = events.recent.limit(1).first
    end

require_ssh_key?() Link

Source: show

    # File app/roles/account.rb, line 17
    def require_ssh_key?
      keys.count == 0
    end

several_namespaces?() Link

Source: show

    # File app/roles/account.rb, line 101
    def several_namespaces?
      namespaces.size > 1
    end