Skip to content

Commit 8e5d53b

Browse files
committed
Allow ExCS admin to update starter project identifier
This modifies `Project::Update#update_project_attributes` so that if the user has permission to update the project and the supplied identifier is not blank, then the identifier is updated. There are obviously some dangers associated with changing an existing project's identifier, but I think it's still useful for an ExCS admin to be able to do it.
1 parent ffa3fc4 commit 8e5d53b

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/concepts/project/operations/update.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ def update_project_attributes(response, update_hash, current_user)
6060
return if response.failure?
6161

6262
response[:project].assign_attributes(update_hash.slice(:name, :instructions))
63+
64+
ability = Ability.new(current_user)
65+
return unless ability.can?(:update, response[:project])
66+
return if update_hash[:identifier].blank?
67+
68+
response[:project].identifier = update_hash[:identifier]
6369
end
6470

6571
def update_component_attributes(response, update_hash)

spec/features/project/updating_a_project_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@
104104
expect(response).to have_http_status(:success)
105105
end
106106

107+
it 'sets the project identifier to the specified value' do
108+
put("/api/projects/#{project.identifier}?project_type=scratch", headers:, params:)
109+
data = JSON.parse(response.body, symbolize_names: true)
110+
111+
expect(data[:identifier]).to eq('test-project')
112+
end
113+
107114
it 'sets the project name to the specified value' do
108115
put("/api/projects/#{project.identifier}?project_type=scratch", headers:, params:)
109116
data = JSON.parse(response.body, symbolize_names: true)

0 commit comments

Comments
 (0)