Skip to content

Commit

Permalink
Create User link for non-deleted ones
Browse files Browse the repository at this point in the history
NB: Admin user can access deleted user page anyway
  • Loading branch information
ncounter committed Feb 23, 2024
1 parent ae034c6 commit d562e13
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/api/app/components/notification_notifiable_link_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def notifiable_link_path
when 'Event::ReportForProject', 'Event::ReportForPackage'
@notification.event_type.constantize.notification_link_path(@notification)
when 'Event::ReportForUser'
Rails.application.routes.url_helpers.user_path(@notification.event_payload['user_login'], notification_id: @notification.id)
Rails.application.routes.url_helpers.user_path(@notification.event_payload['user_login'], notification_id: @notification.id) if !user_event.is_deleted? || current_user_is_admin
when 'Event::ReportForRequest'
bs_request = @notification.notifiable.reportable
Rails.application.routes.url_helpers.request_show_path(bs_request.number, notification_id: @notification.id)
Expand Down Expand Up @@ -206,5 +206,17 @@ def path_to_commentables_on_reports(event_payload:, notification_id:)
anchor: 'comments-list')
end
end

# rubocop:disable ViewComponent/AvoidGlobalState
def user_event
User.find_by_login(@notification.event_payload['user_login'])
end
# rubocop:enable ViewComponent/AvoidGlobalState

# rubocop:disable ViewComponent/AvoidGlobalState
def current_user_is_admin
User.admin_session?
end
# rubocop:enable ViewComponent/AvoidGlobalState
end
# rubocop:enable Metrics/ClassLength
4 changes: 4 additions & 0 deletions src/api/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ def is_active?
self.state == 'confirmed'
end

def is_deleted?
state == 'deleted'
end

def is_in_group?(group)
case group
when String
Expand Down

0 comments on commit d562e13

Please sign in to comment.