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

Endpoint for fetching current party roles #983

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

adamhaeger
Copy link
Contributor

@adamhaeger adamhaeger commented Dec 16, 2024

Adds endpoint for fetching the users current party roles.

You need this PR in localtest to test:

Altinn/app-localtest#131

Description

  • Adds endpoint /api/authorization/roles to AuthorizationController
  • Refactored functionality to fetch current party to reusable function
  • Implemented fetching of the current parties.

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

@adamhaeger adamhaeger changed the title Endpoint working Endpoint for fetching current party roles Dec 16, 2024
@adamhaeger adamhaeger added the kind/feature-request New feature or request label Dec 16, 2024
Copy link
Contributor

@danielskovli danielskovli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/Altinn.App.Api/Controllers/AuthorizationController.cs Outdated Show resolved Hide resolved
src/Altinn.App.Api/Controllers/AuthorizationController.cs Outdated Show resolved Hide resolved
@adamhaeger adamhaeger added the feature Label Pull requests with new features. Used when generation releasenotes label Dec 17, 2024
@adamhaeger adamhaeger marked this pull request as ready for review December 17, 2024 09:16
Comment on lines +218 to +226
catch (Exception ex)
{
_logger.LogError(
ex,
"An error occurred while retrieving roles for userId {UserId} and partyId {PartyId}",
userId,
userPartyId
);
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
/// <param name="userId">The user id.</param>
/// <param name="userPartyId">The user party id.</param>
/// <returns>A list of roles for the user on the specified party.</returns>
public async Task<List<Role>> GetUserRolesAsync(int userId, int userPartyId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should return IEnumerable<> or IReadOnlyList<> instead, to express the intended usage

/// <returns>A list of roles for the user on the specified party.</returns>
public async Task<List<Role>> GetUserRolesAsync(int userId, int userPartyId)
{
List<Role> roles = new();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we wrap the body in activity (distributed trace spans). You can probably find example usages of Telemetry

"An error occurred while retrieving roles for userId {UserId} and partyId {PartyId}",
userId,
userPartyId
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the error handling here. If the API fails for some reason we return an empty list, which might make it look like the user has no roles when in fact the problem was that we couldn't find out at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Label Pull requests with new features. Used when generation releasenotes kind/feature-request New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants