module Account

Public Instance Methods

block() click to toggle source

Remove user from all projects and set blocked attribute to true

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

  self.blocked = true
  save
end
can_create_group?() click to toggle source
# File app/roles/account.rb, line 25
def can_create_group?
  is_admin?
end
can_create_project?() click to toggle source
# File app/roles/account.rb, line 21
def can_create_project?
  projects_limit > my_own_projects.count
end
cared_merge_requests() click to toggle source
# File app/roles/account.rb, line 37
def cared_merge_requests
  MergeRequest.where("author_id = :id or assignee_id = :id", id: self.id).opened
end
first_name() click to toggle source
# File app/roles/account.rb, line 33
def first_name
  name.split.first unless name.blank?
end
identifier() click to toggle source

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._\@+-]*$
# 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?() click to toggle source
# File app/roles/account.rb, line 13
def is_admin?
  admin
end
last_activity_project() click to toggle source
# File app/roles/account.rb, line 29
def last_activity_project
  projects.first
end
project_ids() click to toggle source
# File app/roles/account.rb, line 41
def project_ids
  projects.map(&:id)
end
projects_limit_percent() click to toggle source
# File app/roles/account.rb, line 56
def projects_limit_percent
  return 100 if projects_limit.zero?
  (my_own_projects.count.to_f / projects_limit) * 100
end
projects_with_events() click to toggle source
# File app/roles/account.rb, line 70
def projects_with_events
  projects.includes(:events).order("events.created_at DESC")
end
recent_push(project_id = nil) click to toggle source
# File app/roles/account.rb, line 61
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?() click to toggle source
# File app/roles/account.rb, line 17
def require_ssh_key?
  keys.count == 0
end