Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
Disallow changing roles of team members after role creation
Browse files Browse the repository at this point in the history
Could also solve one of the bugs behind #205
  • Loading branch information
carpodaster committed Mar 12, 2016
1 parent b7fc80c commit a85416d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
12 changes: 11 additions & 1 deletion app/controllers/teams_controller.rb
Expand Up @@ -79,11 +79,21 @@ def team_params
:checked, :'starts_on(1i)', :'starts_on(2i)', :'starts_on(3i)',
:'finishes_on(1i)', :'finishes_on(2i)', :'finishes_on(3i)', :invisible,
:project_name,
roles_attributes: [:id, :name, :github_handle, :_destroy],
roles_attributes: role_attributes_list,
sources_attributes: [:id, :kind, :url, :_destroy]
)
end

def role_attributes_list
unless current_user.admin? ||
# If it contains an ID, the user is updating an existing role
params.fetch(:roles_attributes, {}).none? { |_, attributes| attributes.has_key? 'id' }
[:id, :github_handle, :_destroy] # do not allow to update the actual role
else
[:id, :name, :github_handle, :_destroy]
end
end

def set_display_roles
@display_roles = ['student']
@display_roles.map!(&:pluralize)
Expand Down
2 changes: 1 addition & 1 deletion app/views/teams/_form.html.slim
Expand Up @@ -29,7 +29,7 @@
- accessible_roles.each do |role|
.radio
label
= r.radio_button :name, role, required: true
= r.radio_button :name, role, required: true, disabled: (!current_user.admin? && r.object.persisted?)

This comment has been minimized.

Copy link
@carpodaster

carpodaster Mar 12, 2016

Author Member

@klappradla if you can transform that into a nice CanCan / Ability rule, that'd be super nice. But it's also not terribly important :)

= role.capitalize
.help-block Note: Coaches will be informed via email and have to confirm their role.
.form-btn-group
Expand Down

0 comments on commit a85416d

Please sign in to comment.