-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: introduce user domain #287
Conversation
This ensures that test users can be used by the API, the SPA and the E2E project.
# Conflicts: # package.json
Kudos, SonarCloud Quality Gate passed! |
# Conflicts: # .github/actions/build-and-deploy-api/action.yml # .github/workflows/next-deployment.yml # apps/api/src/.env.template # apps/spa/src/app/app.module.ts # apps/spa/src/environments/environment.ts # libs/spa/auth/src/lib/components/dev-login.component.ts # package-lock.json # package.json
df6b5d0
to
50566eb
Compare
# Conflicts: # .github/actions/build-and-deploy-api/action.yml # .github/workflows/next-deployment.yml # apps/api/src/.env.template # apps/spa/src/app/app.module.ts # apps/spa/src/environments/environment.ts # libs/spa/auth/src/lib/components/dev-login.component.ts # package-lock.json # package.json
50566eb
to
f615d71
Compare
# Conflicts: # .github/actions/build-and-deploy-api/action.yml # .github/workflows/next-deployment.yml # apps/api/src/.env.template # apps/spa/src/app/app.module.ts # apps/spa/src/environments/environment.ts # libs/spa/auth/src/lib/components/dev-login.component.ts # package-lock.json # package.json
33a11db
to
05156a7
Compare
9b697ff
to
99a715d
Compare
apps/api/src/app/app.module.ts
Outdated
const IS_NEXT_DEPLOYMENT = process.env.ENVIRONMENT_NAME === 'next'; | ||
const IS_PROD_DEPLOYMENT = process.env.ENVIRONMENT_NAME === 'prod'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we introduce a flag e.g., ENABLE_DEV_LOGIN
and only if this is set to true
we enable dev login, otherwise it is Azure Entra ID? That way we can control the use of Entra ID easier e.g. for local testing as well and use the safer method (Entra ID) by default.
@@ -0,0 +1,11 @@ | |||
import { PresentableException } from '@kordis/api/shared'; | |||
|
|||
export class PresentableInsufficientPermissionException extends PresentableException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this defacto the same as the PresentableUnauthorizedException
?
apps/spa-e2e/src/test-users.ts
Outdated
|
||
export const testUsernames = [...TEST_USERS.map((u) => u.userName)] as const; | ||
export type TestUsernames = (typeof testUsernames)[number]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simplify. Accept suggestion from libs/shared/test-helpers/src/lib/test-users.test-helper.ts
to enable code completion for usernames.
export const testUsernames = [...TEST_USERS.map((u) => u.userName)] as const; | |
export type TestUsernames = (typeof testUsernames)[number]; | |
export type TestUsernames = (typeof TEST_USERS)[number]['userName']; | |
import { UserDeactivated } from './object-type/user-deactivated.object-type'; | ||
|
||
@Resolver(User) | ||
export class UserResolver { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put the assertOrgMembership
to a whole resolver as a Decorator instead of ensuring that within every query/mutation?
} else if (key === 'role') { | ||
updatePayload[`extension_${this.extensionAppId}_Role`] = value; | ||
} else if (key === 'organizationId') { | ||
updatePayload[`extension_${this.extensionAppId}_OrganizationId`] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We never want to update the user's organization id, right? So if the id is not required by Azure, we should not set it here, if it is required, we have to require it in the method's signature as well.
await this.updateUserRequest(userId, updatePayload); | ||
} | ||
|
||
async changeEmail(userId: string, email: string): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about e-mail verification. Does Azure AD take responsibility for that?
*/ | ||
@Injectable() | ||
export class DevUserService extends BaseUserService { | ||
private readonly users: User[] = [...TEST_USERS]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you move the type declaration for the users into the test-helpers
file (probably good idea anyway to ensure correct types) and do a deep copy here, the type should be inferred automatically
import { Role } from '@kordis/shared/auth'; | ||
|
||
// keep in sync with the apps/api/dev-tokens.md file! | ||
export const TEST_USERS = Object.freeze([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you use as const
instead of Object.freeze
the values will be assumed as literals by TypeScript and enable a beautiful code completion.
Also, we should do TEST_UERS: User[]
to ensure these users are all legit (especially when we change the User
object).
} | ||
|
||
async updateUser( | ||
userId: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
userId: string, | |
private async updateUser( |
} else if (key === 'organizationId') { | ||
updatePayload[`extension_${this.extensionAppId}_OrganizationId`] = | ||
value; | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} else if (key === 'organizationId') { | |
updatePayload[`extension_${this.extensionAppId}_OrganizationId`] = | |
value; | |
} else { | |
} else { |
…separation of concerns
libs/api/user/src/lib/infra/service/aadb2c-user.service.spec.ts
Dismissed
Show dismissed
Hide dismissed
libs/api/user/src/lib/infra/service/aadb2c-user.service.spec.ts
Dismissed
Show dismissed
Hide dismissed
libs/api/user/src/lib/infra/service/aadb2c-user.service.spec.ts
Dismissed
Show dismissed
Hide dismissed
libs/api/user/src/lib/infra/service/aadb2c-user.service.spec.ts
Dismissed
Show dismissed
Hide dismissed
libs/api/user/src/lib/infra/service/aadb2c-user.service.spec.ts
Dismissed
Show dismissed
Hide dismissed
Quality Gate passedIssues Measures |
🎉 This PR is included in version 1.2.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Description
Introduces a user domain with a dev in memory user store for local and preview environments, and a service that communicates with the MS Graph API to manage users on our AADB2C tenant. Furthermore, introduces a role hierarchy and a utility decorator to check the minimum required role in the request pipeline.
As a feature, if a user is logged in and gets deactivated, he will be logged out automatically.
Checklist:
The title of this PR and the commit history is conform with
the Conventional Commits specification.
I have performed a self-review of my own code.
My changes generate no new warnings, SonarCloud reports no Vulnerabilities, Bugs or Code Smells.
I have added tests (unit and E2E if user-facing) that prove my fix is effective or that my feature works,
Coverage > 80% and not less than the current coverage of the main branch.
The PR branch is up-to-date with the base branch. In case you merged
main
into your feature branch, make sure you have run the latest NX migrations (nx migrate --run-migrations
).I have included the
reset.d.ts
in thetsconfig.lib.json
I have included the
reset.d.ts
in thetsconfig.lib.json
I have extended the
.eslintrc.json
with.eslintrc.angular.json