Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DPC-4403] Log when invitation already accepted #2341

Merged
merged 7 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions dpc-portal/app/controllers/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,21 +234,32 @@ def load_invitation
def validate_invitation
return unless @invitation.unacceptable_reason

if @invitation.credential_delegate?
Rails.logger.info(['Credential Delegate Invitation expired',
{ actionContext: LoggingConstants::ActionContext::Registration,
actionType: LoggingConstants::ActionType::CdInvitationExpired,
invitation: @invitation.id }])
elsif @invitation.authorized_official?
Rails.logger.info(['Authorized Official Invitation expired',
{ actionContext: LoggingConstants::ActionContext::Registration,
actionType: LoggingConstants::ActionType::AoInvitationExpired,
invitation: @invitation.id }])
end
err_msg, action_type = get_invitation_log_data(@invitation.unacceptable_reason)
Rails.logger.info([err_msg, { actionContext: LoggingConstants::ActionContext::Registration,
actionType: action_type,
invitation: @invitation.id }])

render(Page::Invitations::BadInvitationComponent.new(@invitation, @invitation.unacceptable_reason),
status: :forbidden)
end

def get_invitation_log_data(reason)
unacceptable_reason_map = {
invalid: ['Invalid Invitation', LoggingConstants::ActionType::InvalidInvitation],
ao_renewed: ['Ao Renewed Expired Invitation', LoggingConstants::ActionType::AoRenewedExpiredInvitation],
ao_accepted: ['Authorized Official Invitation already accepted',
LoggingConstants::ActionType::AoAlreadyRegistered],
cd_accepted: ['Credential Delegate Invitation already accepted',
LoggingConstants::ActionType::CdAlreadyRegistered],
ao_expired: ['Authorized Official Invitation expired', LoggingConstants::ActionType::AoInvitationExpired],
cd_expired: ['Credential Delegate Invitation expired', LoggingConstants::ActionType::CdInvitationExpired]
}
unacceptable_reason_map.default = ["Invitation unacceptable: #{reason}",
LoggingConstants::ActionType::UnacceptableInvitation]

unacceptable_reason_map[reason.to_sym]
end

def verify_ao_invitation
redirect_to organization_invitation_url(@organization, @invitation) unless @invitation.authorized_official?
end
Expand Down
5 changes: 5 additions & 0 deletions dpc-portal/config/initializers/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module ActionType
CdCreated = 'CdCreated'
AoLinkedToOrg = 'AoLinkedToOrg'
CdLinkedToOrg = 'CdLinkedToOrg'
AoAlreadyRegistered = 'AoAlreadyRegistered'
CdAlreadyRegistered = 'CdAlreadyRegistered'

BeginLogin = 'BeginLogin'
UserLoggedIn = 'UserLoggedIn'
Expand All @@ -42,5 +44,8 @@ module ActionType

HealthCheckPassed = 'HealthCheckPassed'
HealthCheckFailed = 'HealthCheckFailed'

InvalidInvitation = 'InvalidInvitation'
UnacceptableInvitation = 'UnacceptableInvitation'
end
end
18 changes: 18 additions & 0 deletions dpc-portal/spec/requests/invitations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@
end
it 'should show warning page if accepted' do
invitation.accept!
if invitation.authorized_official?
allow(Rails.logger).to receive(:info)
expect(Rails.logger).to receive(:info).with(
['Authorized Official Invitation already accepted',
{ actionContext: LoggingConstants::ActionContext::Registration,
actionType: LoggingConstants::ActionType::AoAlreadyRegistered,
invitation: invitation.id }]
)
elsif invitation.credential_delegate?
allow(Rails.logger).to receive(:info)
expect(Rails.logger).to receive(:info).with(
['Credential Delegate Invitation already accepted',
{ actionContext: LoggingConstants::ActionContext::Registration,
actionType: LoggingConstants::ActionType::CdAlreadyRegistered,
invitation: invitation.id }]
)
end

send(method, "/organizations/#{org.id}/invitations/#{invitation.id}/#{path_suffix}")
expect(response).to be_forbidden
if invitation.authorized_official?
Expand Down
Loading