class UsersProject

Constants

DEVELOPER
GUEST
MASTER
REPORTER

Public Class Methods

access_roles() click to toggle source
# File app/models/users_project.rb, line 96
def access_roles
  {
    "Guest"     => GUEST,
    "Reporter"  => REPORTER,
    "Developer" => DEVELOPER,
    "Master"    => MASTER
  }
end
bulk_delete(project, user_ids) click to toggle source
# File app/models/users_project.rb, line 53
def bulk_delete(project, user_ids)
  UsersProject.transaction do
    UsersProject.where(:user_id => user_ids, :project_id => project.id).each do |users_project|
      users_project.destroy
    end
  end
end
bulk_import(project, user_ids, project_access) click to toggle source
# File app/models/users_project.rb, line 70
def bulk_import(project, user_ids, project_access)
  UsersProject.transaction do
    user_ids.each do |user_id|
      users_project = UsersProject.new(
        project_access: project_access,
        user_id: user_id
      )
      users_project.project = project
      users_project.save
    end
  end
end
bulk_update(project, user_ids, project_access) click to toggle source
# File app/models/users_project.rb, line 61
def bulk_update(project, user_ids, project_access)
  UsersProject.transaction do
    UsersProject.where(:user_id => user_ids, :project_id => project.id).each do |users_project|
      users_project.project_access = project_access
      users_project.save
    end
  end
end
import_team(source_project, target_project) click to toggle source
# File app/models/users_project.rb, line 24
def import_team(source_project, target_project)
  UsersProject.without_repository_callback do
    UsersProject.transaction do
      team = source_project.users_projects.all

      team.each do |tm|
        # Skip if user already present in team
        next if target_project.users.include?(tm.user)

        new_tm = tm.dup
        new_tm.id = nil
        new_tm.project_id = target_project.id
        new_tm.save
      end
    end
  end

  target_project.update_repository
  true
rescue
  false
end
user_bulk_import(user, project_ids, project_access) click to toggle source
# File app/models/users_project.rb, line 83
def user_bulk_import(user, project_ids, project_access)
  UsersProject.transaction do
    project_ids.each do |project_id|
      users_project = UsersProject.new(
        project_access: project_access,
      )
      users_project.project_id = project_id
      users_project.user_id = user.id
      users_project.save
    end
  end
end
without_repository_callback() { || ... } click to toggle source
# File app/models/users_project.rb, line 47
def without_repository_callback
  UsersProject.skip_callback(:destroy, :after, :update_repository)
  yield
  UsersProject.set_callback(:destroy, :after, :update_repository)
end

Public Instance Methods

project_access_human() click to toggle source
# File app/models/users_project.rb, line 114
def project_access_human
  Project.access_options.key(self.project_access)
end
repo_access_human() click to toggle source
# File app/models/users_project.rb, line 118
def repo_access_human
  self.class.access_roles.invert[self.project_access]
end
role_access() click to toggle source
# File app/models/users_project.rb, line 106
def role_access
  project_access
end
update_repository() click to toggle source
# File app/models/users_project.rb, line 110
def update_repository
  git_host.update_repository(project)
end