Skip to content

Commit

Permalink
Handle notification_id query param gracefully for project show
Browse files Browse the repository at this point in the history
There is no need to block users from viewing a project when
someone is sharing a link from his notifications with the
`notification_id` attached as a query param. The `notification_id`
query param is used to render the notification toolbar for an
authorized users. If someone without authorization is using the
same link, we should simply not render the toolbar, but still show
the project show view.
  • Loading branch information
krauselukas committed May 8, 2024
1 parent 8612fd9 commit d190659
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/api/app/controllers/webui/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ def show
@has_patchinfo = @project.patchinfos.exists?
@comments = @project.comments
@comment = Comment.new

if User.session && params[:notification_id]
@current_notification = Notification.find(params[:notification_id])
authorize @current_notification, :update?, policy_class: NotificationPolicy
end
@current_notification = handle_notification

respond_to do |format|
format.html
Expand Down Expand Up @@ -474,4 +470,14 @@ def set_project_by_name
rescue Project::UnknownObjectError
@project = nil
end

def handle_notification
return unless User.session && params[:notification_id]

current_notification = Notification.find(params[:notification_id])

return unless NotificationPolicy.new(User.session, current_notification).update?

current_notification
end
end

0 comments on commit d190659

Please sign in to comment.