Skip to content
This repository was archived by the owner on Jun 24, 2024. It is now read-only.

Add option to use Roster ID for Assignment-Repo suffix #1722

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/controllers/assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def assistant
def new_assignment_params
params
.require(:assignment)
.permit(:title, :slug, :public_repo, :students_are_repo_admins, :invitations_enabled)
.permit(:title, :slug, :public_repo, :students_are_repo_admins, :invitations_enabled, :use_roster_id)
.merge(creator: current_user,
organization: @organization,
starter_code_repo_id: starter_code_repo_id_param,
Expand Down Expand Up @@ -130,7 +130,7 @@ def starter_code_repo_id_param
def update_assignment_params
params
.require(:assignment)
.permit(:title, :slug, :public_repo, :students_are_repo_admins, :deadline, :invitations_enabled)
.permit(:title, :slug, :public_repo, :students_are_repo_admins, :deadline, :invitations_enabled, :use_roster_id)
.merge(starter_code_repo_id: starter_code_repo_id_param)
end

Expand Down
12 changes: 10 additions & 2 deletions app/models/assignment_repo/creator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,18 @@ def verify_organization_has_private_repos_available!
#####################################

# rubocop:disable AbcSize
# rubocop:disable MethodLength
def generate_github_repository_name
suffix_count = 0

owner = organization.github_organization.login_no_cache
repository_name = "#{assignment.slug}-#{user.github_user.login_no_cache}"
owner = organization.github_organization.login_no_cache

entry = RosterEntry.find_by(roster: organization.roster, user: user)
repository_name = if assignment.use_roster_id && entry.present?
"#{assignment.slug}-#{entry.identifier}"
else
"#{assignment.slug}-#{user.github_user.login_no_cache}"
end

loop do
name = "#{owner}/#{suffixed_repo_name(repository_name, suffix_count)}"
Expand All @@ -213,6 +220,7 @@ def generate_github_repository_name
suffixed_repo_name(repository_name, suffix_count)
end
# rubocop:enable AbcSize
# rubocop:enable MethodLength

def suffixed_repo_name(repository_name, suffix_count)
return repository_name if suffix_count.zero?
Expand Down
6 changes: 6 additions & 0 deletions app/views/assignments/_assignment_form_options.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
</div>
</dl>

<dl class="form">
<div class="form-checkbox">
<label><%= f.check_box :use_roster_id %> Use Roster-ID (if linked) instead of Student Github username in repository name</label>
</div>
</dl>

<dl class="form">
<dt><label>Add your starter code from GitHub <small>(optional)</small> </label></dt>
<dd><input class="textfield js-autocomplete-textfield form-control input-contrast input-block" type="text" name="repo_name" value="<%= @assignment.starter_code_repository.try(:full_name) %>" placeholder="<%= @assignment.starter_code_repository.try(:full_name) || 'Search repositories'%>" autocomplete="off" data-autocomplete-search-endpoint="github_repos"></dd>
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20181220032936_add_use_roster_id_to_assignments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddUseRosterIdToAssignments < ActiveRecord::Migration[5.1]

def change
add_column :assignments, :use_roster_id, :boolean, null: false, default: false
end

end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20181101185917) do
ActiveRecord::Schema.define(version: 20181220032936) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -56,6 +56,7 @@
t.string "slug", null: false
t.boolean "students_are_repo_admins", default: false, null: false
t.boolean "invitations_enabled", default: true
t.boolean "use_roster_id", default: false, null:false
t.index ["deleted_at"], name: "index_assignments_on_deleted_at"
t.index ["organization_id"], name: "index_assignments_on_organization_id"
t.index ["slug"], name: "index_assignments_on_slug"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
title: "Learn Elm",
starter_code_repo_id: 1_062_897,
organization: organization,
students_are_repo_admins: true
students_are_repo_admins: true,
use_roster_id: false
}

create(:assignment, options)
Expand Down
3 changes: 2 additions & 1 deletion spec/models/assignment_repo/creator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
starter_code_repo_id: 1_062_897,
organization: organization,
students_are_repo_admins: true,
public_repo: false
public_repo: false,
use_roster_id: false
}

create(:assignment, options)
Expand Down