class Group

Maintains group information for a given user on a specific assignment

Constants

AUTOGENERATED_PREFIX

prefix used for autogenerated group_names

Public Instance Methods

access_repo() { |repository| ... } click to toggle source

Yields a repository object, if possible, and closes it after it is finished

# File app/models/group.rb, line 121
def access_repo
  repository = self.repo
  yield repository
  repository.close()
end
build_repository() click to toggle source
# File app/models/group.rb, line 70
def build_repository
  # create repositories and write permissions if and only if we are admin
  return true if !MarkusConfigurator.markus_config_repository_admin?

  # This might cause repository collision errors, because when the group
  # maximum for an assignment is set to be one, the student's username
  # will be used as the repository name. This will raise a RepositoryCollision
  # if an instructor uses a csv file with a student appearing as the only member of
  # two different groups (remember: uploading via csv purges old groupings).
  #
  # Because we use the group id as part of the repository name in all other cases,
  # a repo collision *should* never occur then.
  #
  # For more info about the exception
  # See 'self.create' of lib/repo/subversion_repository.rb.
  begin
    Repository.get_class(MarkusConfigurator.markus_config_repository_type, self.repository_config).create(File.join(MarkusConfigurator.markus_config_repository_storage, repository_name))
  rescue Repository::RepositoryCollision => e
    # log the collision
    errors.add(:base, self.repo_name)
    m_logger = MarkusLogger.instance
    m_logger.log("Creating group '#{self.group_name}' caused repository collision " +
                 "(Repository name was: '#{self.repo_name}'). Error message: '#{e.message}'",
                 MarkusLogger::ERROR)
  end

  # Each admin user will have read and write permissions on each repo
  user_permissions = {}
  Admin.all.each do |admin|
    user_permissions[admin.user_name] = Repository::Permission::READ_WRITE
  end
  # Each grader will have read and write permissions on each repo
  Ta.all.each do |ta|
    user_permissions[ta.user_name] = Repository::Permission::READ_WRITE
  end
  group_repo = Repository.get_class(MarkusConfigurator.markus_config_repository_type, self.repository_config)
  group_repo.set_bulk_permissions([File.join(MarkusConfigurator.markus_config_repository_storage, self.repository_name)], user_permissions)
  true
end
get_autogenerated_group_name() click to toggle source

Returns an autogenerated name for the group using Group::AUTOGENERATED_PREFIX This only works, after a barebone group record has been created in the database

# File app/models/group.rb, line 43
def get_autogenerated_group_name
  Group::AUTOGENERATED_PREFIX + self.id.to_s.rjust(4, '0')
end
grouping_for_assignment(aid) click to toggle source
# File app/models/group.rb, line 47
def grouping_for_assignment(aid)
  groupings.first(:conditions => {:assignment_id => aid})
end
repo() click to toggle source

Return a repository object, if possible

# File app/models/group.rb, line 111
def repo
  repo_loc = File.join(MarkusConfigurator.markus_config_repository_storage, self.repository_name)
  if Repository.get_class(MarkusConfigurator.markus_config_repository_type, self.repository_config).repository_exists?(repo_loc)
    Repository.get_class(MarkusConfigurator.markus_config_repository_type, self.repository_config).open(repo_loc)
  else
    raise 'Repository not found and MarkUs not in authoritative mode!' # repository not found, and we are not repo-admin
  end
end
repository_admin?() click to toggle source
# File app/models/group.rb, line 56
def repository_admin?
  MarkusConfigurator.markus_config_repository_admin?
end
repository_config() click to toggle source

Returns configuration for repository configuration

# File app/models/group.rb, line 62
def repository_config
  conf = Hash.new
  conf['IS_REPOSITORY_ADMIN'] = MarkusConfigurator.markus_config_repository_admin?
  conf['REPOSITORY_PERMISSION_FILE'] = MarkusConfigurator.markus_config_repository_permission_file
  conf['REPOSITORY_STORAGE'] = MarkusConfigurator.markus_config_repository_storage
  conf
end
repository_external_access_url() click to toggle source

Returns the URL for externally accessible repos

# File app/models/group.rb, line 52
def repository_external_access_url
  MarkusConfigurator.markus_config_repository_external_base_url + '/' + repository_name
end
repository_name() click to toggle source

Returns the repository name for this group

# File app/models/group.rb, line 37
def repository_name
  self.repo_name
end
set_repo_name() click to toggle source

Set repository name in database after a new group is created

# File app/models/group.rb, line 27
def set_repo_name
  # If repo_name has been set already, use this name instead
  # of the autogenerated name.
  if self.repo_name.nil?
    self.repo_name = get_autogenerated_group_name
  end
  self.save(:validate => false) # need to save!
end