Skip to content

Commit

Permalink
Fix permissions to show Avatar tab in 'Edit Profile' section
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorbg committed Oct 18, 2024
1 parent 7bef728 commit 6c62294
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,10 @@ def can_edit_any_user?
end

def can_change_users_avatar?(user)
user.wca_id.present? && self.editable_fields_of_user(user).include?(:current_avatar)
# We use the ability to `remove_avatar` as a general check for whether edits are allowed.
# Otherwise, checking for competitions of `current_avatar` and `pending_avatar` might be
# too cumbersome depending on the context (ie depending on where this method is being called from)
self.editable_fields_of_user(user).include?(:remove_avatar)
end

def organizer_for?(user)
Expand Down Expand Up @@ -1068,11 +1071,12 @@ def editable_fields_of_user(user)

private def editable_avatar_fields(user)
fields = Set.new
if admin? || results_team?
fields += %i(current_avatar)
end
if user == self || admin? || results_team? || is_senior_delegate_for?(user)
fields += %i(pending_avatar)
fields += %i(pending_avatar avatar_thumbnail remove_avatar)

if can_admin_results?
fields += %i(current_avatar)
end
end
fields
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
userId: @user.id,
showStaffGuidelines: @user.staff_or_any_delegate?,
uploadDisabled: !editable_fields.include?(:pending_avatar),
canRemoveAvatar: @user.current_avatar.present? && editable_fields.include?(:current_avatar),
canRemoveAvatar: editable_fields.include?(:remove_avatar),
canAdminAvatars: current_user.can_admin_results?,
}) %>
</div>
Expand Down

0 comments on commit 6c62294

Please sign in to comment.