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

draft orgUser query #4494

Closed
wants to merge 3 commits into from
Closed

draft orgUser query #4494

wants to merge 3 commits into from

Conversation

eliykat
Copy link
Member

@eliykat eliykat commented Jul 11, 2024

For discussion only, ignore.

🎟️ Tracking

📔 Objective

📸 Screenshots

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link
Contributor

github-actions bot commented Jul 11, 2024

Logo
Checkmarx One – Scan Summary & Detailsc9515955-7b8c-471e-8a0f-ff49da6c591f

New Issues

Severity Issue Source File / Package Checkmarx Insight
MEDIUM Missing_HSTS_Header /src/Api/Startup.cs: 66 Attack Vector

Fixed Issues

Severity Issue Source File / Package
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 217
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 91
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 243
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 325
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 343
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 120
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 358
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 285
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 529
MEDIUM CSRF /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 543
MEDIUM Privacy_Violation /src/Core/Services/Implementations/UserService.cs: 709
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 285
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 271
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 285
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 271
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 271
LOW Log_Forging /src/Api/AdminConsole/Controllers/OrganizationUsersController.cs: 285

Copy link
Member Author

@eliykat eliykat left a comment

Choose a reason for hiding this comment

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

All looks pretty good to me, a few comments below but nothing major. Please feel free to put up a PR for review whenever you're ready.

Comment on lines 37 to 38
// Convert the OrganizationUserUserDetails permissions json string
this.Permissions = CoreHelpers.LoadClassFromJsonData<Permissions>(OrganizationUserUserDetails.Permissions);
Copy link
Member Author

Choose a reason for hiding this comment

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

The class already has a helper for this: OrganizationUserUserDetails.GetPermissions(). Although my preference is for the consuming code to do this as/when required, it's duplicative here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know how I missed that. That is 100 times easier. Thanks.

Comment on lines 103 to 106
response.Type = GetFlexibleCollectionsUserType(response.Type, response.Permissions);
response.Type.GetFlexibleCollectionsUserType(response.Permissions);
Copy link
Member Author

Choose a reason for hiding this comment

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

You're no longer doing anything with this return value.

Copy link
Contributor

Choose a reason for hiding this comment

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

haha yea I missed that part. Thanks.

Comment on lines 142 to 153
// I was not sure about automapper being a possible use case here?
// If not I am sure I can likely implement a more elegant conversion solution
var responses = new List<OrganizationUserUserDetailsResponseModel>();
foreach (var queryResponse in queryResponses)
{
responses.Add(new OrganizationUserUserDetailsResponseModel(
queryResponse.OrganizationUserUserDetails,
queryResponse.TwoFactorEnabled,
permissions: queryResponse.Permissions
)
);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

automapper is definitely overkill. What about:

var responses = queryResponses.Select(r => new OrganizationUserUserDetailsResponseModel(queryResponse.OrganizationUserUserDetails, queryResponse.TwoFactorEnabled);

Comment on lines 90 to 95
// Since the OrganizationUserUserDetailsQueryResponse object already has the permissions
// converted from json. Add it here as an optional param. If included the base method will
// use the permissions if not it will conver
public OrganizationUserUserDetailsResponseModel(OrganizationUserUserDetails organizationUser,
bool twoFactorEnabled, string obj = "organizationUserUserDetails")
: base(organizationUser, obj)
bool twoFactorEnabled, string obj = "organizationUserUserDetails", Permissions permissions = null)
: base(organizationUser, obj, permissions: permissions)
Copy link
Member Author

Choose a reason for hiding this comment

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

Again, we avoid all of this if we omit it from the query and let consumers decide if/when they want to deserialize this.

Comment on lines 58 to 66
// Should the query authorize? Or should this be the responsibility of the controller?
// Maybe having the query authorize would ensure safety?
// Code from the controller for auth:
// var authorized = (await _authorizationService.AuthorizeAsync(
// User, OrganizationUserOperations.ReadAll(orgId))).Succeeded;
// if (!authorized)
// {
// throw new NotFoundException();
// }
Copy link
Member Author

@eliykat eliykat Jul 11, 2024

Choose a reason for hiding this comment

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

For now at least, I think this should continue to live in the controller; our private and public api use different authorization patterns (private uses a mix of handrolled and resource-based authorization, public uses policy-based authorization), and introducing them at the query level tightly couples the query logic with this particular authorization pattern.

Maybe there's some opportunity to align this in the future, I'm not sure. Happy to discuss if you have any other thoughts here.

await _userService.TwoFactorIsEnabledAsync(o));

// Using the new extension method
orgUser.OrganizationUserUserDetails.Type.GetFlexibleCollectionsUserType(orgUser.Permissions);
Copy link
Member Author

Choose a reason for hiding this comment

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

Unused return value

@eliykat eliykat closed this Aug 15, 2024
@eliykat eliykat deleted the tools/pm-9641/org-user-query branch August 15, 2024 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants