Skip to content

Commit

Permalink
Merge pull request #16111 from krauselukas/notifications/gracefully_h…
Browse files Browse the repository at this point in the history
…andle_notification_toolbar

Handle `notification_id` query param and notifications toolbar gracefully
  • Loading branch information
krauselukas committed May 8, 2024
2 parents 357ccdd + d190659 commit c11087e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
15 changes: 11 additions & 4 deletions src/api/app/controllers/webui/package_controller.rb
Expand Up @@ -75,10 +75,7 @@ def show
@comments = @package.comments.includes(:user)
@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

@services = @files.any? { |file| file['name'] == '_service' }

Expand Down Expand Up @@ -540,4 +537,14 @@ def get_diff(project, package, options = {})
end
true
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
16 changes: 11 additions & 5 deletions src/api/app/controllers/webui/project_controller.rb
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
9 changes: 6 additions & 3 deletions src/api/app/controllers/webui/reports_controller.rb
Expand Up @@ -8,7 +8,7 @@ class Webui::ReportsController < Webui::WebuiController
def show
authorize @report

handle_notification
@current_notification = handle_notification
end

def create
Expand Down Expand Up @@ -49,7 +49,10 @@ def set_report
def handle_notification
return unless User.session && params[:notification_id]

@current_notification = Notification.find(params[:notification_id])
authorize @current_notification, :update?, policy_class: NotificationPolicy
current_notification = Notification.find(params[:notification_id])

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

current_notification
end
end
11 changes: 7 additions & 4 deletions src/api/app/controllers/webui/request_controller.rb
Expand Up @@ -50,7 +50,7 @@ def show
@comments = @bs_request.comments
@comment = Comment.new

handle_notification
@current_notification = handle_notification

@actions = @bs_request.webui_actions(filelimit: @diff_limit, tarlimit: @diff_limit, diff_to_superseded: @diff_to_superseded, diffs: false)
@action = @actions.first
Expand Down Expand Up @@ -508,8 +508,11 @@ def cache_diff_data
def handle_notification
return unless User.session && params[:notification_id]

@current_notification = Notification.find(params[:notification_id])
authorize @current_notification, :update?, policy_class: NotificationPolicy
current_notification = Notification.find(params[:notification_id])

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

current_notification
end

def prepare_request_data
Expand Down Expand Up @@ -544,7 +547,7 @@ def prepare_request_data
# Handling build results
@staging_project = @bs_request.staging_project.name unless @bs_request.staging_project_id.nil?

handle_notification
@current_notification = handle_notification
end

def set_influxdb_data_request_actions
Expand Down
9 changes: 6 additions & 3 deletions src/api/app/controllers/webui/users_controller.rb
Expand Up @@ -32,7 +32,7 @@ def show
@activities_per_year = UserYearlyContribution.new(@displayed_user, @first_day).call
@date = params[:date]
@activities_per_day = UserDailyContribution.new(@displayed_user, @date).call
handle_notification
@current_notification = handle_notification
end

def new
Expand Down Expand Up @@ -204,8 +204,11 @@ def assign_admin_attributes
def handle_notification
return unless User.session && params[:notification_id]

@current_notification = Notification.find(params[:notification_id])
authorize @current_notification, :update?, policy_class: NotificationPolicy
current_notification = Notification.find(params[:notification_id])

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

current_notification
end

def paged_comments
Expand Down

0 comments on commit c11087e

Please sign in to comment.