2012-09-04 00:04:36 -04:00
|
|
|
module Account
|
|
|
|
# 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._\@+-]*$
|
2012-06-07 08:44:57 -04:00
|
|
|
def identifier
|
2012-09-04 00:04:36 -04:00
|
|
|
# Replace non-word chars with underscores, then make sure it starts with
|
|
|
|
# valid chars
|
|
|
|
email.gsub(/\W/, '_').gsub(/\A([\W\_])+/, '')
|
2012-06-07 08:44:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def is_admin?
|
|
|
|
admin
|
|
|
|
end
|
|
|
|
|
|
|
|
def require_ssh_key?
|
|
|
|
keys.count == 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_create_project?
|
|
|
|
projects_limit > my_own_projects.count
|
|
|
|
end
|
|
|
|
|
2012-10-09 02:46:20 -04:00
|
|
|
def can_create_group?
|
|
|
|
is_admin?
|
|
|
|
end
|
|
|
|
|
2012-06-07 08:44:57 -04:00
|
|
|
def last_activity_project
|
|
|
|
projects.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def first_name
|
|
|
|
name.split.first unless name.blank?
|
|
|
|
end
|
|
|
|
|
|
|
|
def cared_merge_requests
|
2012-08-10 18:07:50 -04:00
|
|
|
MergeRequest.where("author_id = :id or assignee_id = :id", id: self.id).opened
|
2012-06-07 08:44:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def project_ids
|
|
|
|
projects.map(&:id)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove user from all projects and
|
|
|
|
# set blocked attribute to true
|
|
|
|
def block
|
2012-10-08 20:10:04 -04:00
|
|
|
users_projects.find_each do |membership|
|
2012-06-07 08:44:57 -04:00
|
|
|
return false unless membership.destroy
|
|
|
|
end
|
|
|
|
|
|
|
|
self.blocked = true
|
|
|
|
save
|
|
|
|
end
|
|
|
|
|
|
|
|
def projects_limit_percent
|
|
|
|
return 100 if projects_limit.zero?
|
|
|
|
(my_own_projects.count.to_f / projects_limit) * 100
|
|
|
|
end
|
2012-06-12 10:43:16 -04:00
|
|
|
|
|
|
|
def recent_push project_id = nil
|
2012-06-21 11:41:22 -04:00
|
|
|
# Get push events not earlier than 2 hours ago
|
|
|
|
events = recent_events.code_push.where("created_at > ?", Time.now - 2.hours)
|
2012-08-10 18:07:50 -04:00
|
|
|
events = events.where(project_id: project_id) if project_id
|
2012-06-12 10:43:16 -04:00
|
|
|
|
|
|
|
# Take only latest one
|
|
|
|
events = events.recent.limit(1).first
|
|
|
|
end
|
2012-07-20 01:39:34 -04:00
|
|
|
|
|
|
|
def projects_with_events
|
|
|
|
projects.includes(:events).order("events.created_at DESC")
|
|
|
|
end
|
2012-06-07 08:44:57 -04:00
|
|
|
end
|