0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor(core): update naming and fix typos

This commit is contained in:
Gao Sun 2024-06-21 20:13:52 +08:00
parent ec95536b84
commit fae11359b2
No known key found for this signature in database
GPG key ID: 13EBE123E4773688
15 changed files with 32 additions and 28 deletions

View file

@ -174,7 +174,7 @@ export class OrganizationInvitationLibrary {
});
if (entity.organizationRoles.length > 0) {
await organizationQueries.relations.rolesUsers.insert(
await organizationQueries.relations.usersRoles.insert(
...entity.organizationRoles.map((role) => ({
organizationId: entity.organizationId,
organizationRoleId: role.id,

View file

@ -138,7 +138,7 @@ export const createUserLibrary = (queries: Queries) => {
const usersRoles = await findUsersRolesByUserId(userId);
const rolesScopes = await findRolesScopesByRoleIds(usersRoles.map(({ roleId }) => roleId));
const organizationScopes = findFromOrganizations
? await organizations.relations.rolesUsers.getUserResourceScopes(
? await organizations.relations.usersRoles.getUserResourceScopes(
userId,
resourceIndicator,
organizationId
@ -295,7 +295,7 @@ export const createUserLibrary = (queries: Queries) => {
}))
);
if (data.length > 0) {
await organizations.relations.rolesUsers.insert(...data);
await organizations.relations.usersRoles.insert(...data);
}
return jitOrganizations;

View file

@ -317,7 +317,7 @@ describe('organization token grant', () => {
Sinon.stub(tenant.queries.organizations.relations.users, 'exists').resolves(true);
Sinon.stub(tenant.queries.applications, 'findApplicationById').resolves(mockApplication);
Sinon.stub(tenant.queries.organizations.relations.rolesUsers, 'getUserScopes').resolves([
Sinon.stub(tenant.queries.organizations.relations.usersRoles, 'getUserScopes').resolves([
{ tenantId: 'default', id: 'foo', name: 'foo', description: 'foo' },
{ tenantId: 'default', id: 'bar', name: 'bar', description: 'bar' },
{ tenantId: 'default', id: 'baz', name: 'baz', description: 'baz' },

View file

@ -338,7 +338,7 @@ export const buildHandler: (
/* === RFC 0001 === */
const audience = buildOrganizationUrn(organizationId);
/** All available scopes for the user in the organization. */
const availableScopes = await queries.organizations.relations.rolesUsers
const availableScopes = await queries.organizations.relations.usersRoles
.getUserScopes(organizationId, account.accountId)
.then((scopes) => scopes.map(({ name }) => name));

View file

@ -9,7 +9,7 @@ import { type CommonQueryMethods, sql } from '@silverhand/slonik';
import RelationQueries from '#src/utils/RelationQueries.js';
import { convertToIdentifiers } from '#src/utils/sql.js';
export class RoleApplicationRelationQueries extends RelationQueries<
export class ApplicationRoleRelationQueries extends RelationQueries<
[typeof Organizations, typeof OrganizationRoles, typeof Applications]
> {
constructor(pool: CommonQueryMethods) {

View file

@ -32,11 +32,11 @@ import { TwoRelationsQueries } from '#src/utils/RelationQueries.js';
import SchemaQueries from '#src/utils/SchemaQueries.js';
import { conditionalSql, convertToIdentifiers } from '#src/utils/sql.js';
import { ApplicationRoleRelationQueries } from './application-role-relations.js';
import { EmailDomainQueries } from './email-domains.js';
import { RoleApplicationRelationQueries } from './role-application-relations.js';
import { RoleUserRelationQueries } from './role-user-relations.js';
import { SsoConnectorQueries } from './sso-connectors.js';
import { UserRelationQueries } from './user-relations.js';
import { UserRoleRelationQueries } from './user-role-relations.js';
/**
* The schema field keys that can be used for searching roles.
@ -285,9 +285,8 @@ export default class OrganizationQueries extends SchemaQueries<
),
/** Queries for organization - user relations. */
users: new UserRelationQueries(this.pool),
// TODO: Rename to `usersRoles`
/** Queries for organization - organization role - user relations. */
rolesUsers: new RoleUserRelationQueries(this.pool),
usersRoles: new UserRoleRelationQueries(this.pool),
/** Queries for organization - application relations. */
apps: new TwoRelationsQueries(
this.pool,
@ -295,9 +294,8 @@ export default class OrganizationQueries extends SchemaQueries<
Organizations,
Applications
),
// TODO: Rename to `appsRoles`
/** Queries for organization - organization role - application relations. */
rolesApps: new RoleApplicationRelationQueries(this.pool),
appsRoles: new ApplicationRoleRelationQueries(this.pool),
invitationsRoles: new TwoRelationsQueries(
this.pool,
OrganizationInvitationRoleRelations.table,

View file

@ -16,7 +16,7 @@ import { sql, type CommonQueryMethods } from '@silverhand/slonik';
import RelationQueries from '#src/utils/RelationQueries.js';
import { conditionalSql, convertToIdentifiers } from '#src/utils/sql.js';
export class RoleUserRelationQueries extends RelationQueries<
export class UserRoleRelationQueries extends RelationQueries<
[typeof Organizations, typeof OrganizationRoles, typeof Users]
> {
constructor(pool: CommonQueryMethods) {

View file

@ -178,7 +178,7 @@ async function handleSubmitRegister(
// This is only for Cloud integration tests and data alignment, OSS still uses the legacy Management API user role.
const organizationId = getTenantOrganizationId(defaultTenantId);
await organizations.relations.users.insert({ organizationId, userId: id });
await organizations.relations.rolesUsers.insert({
await organizations.relations.usersRoles.insert({
organizationId,
organizationRoleId: getTenantRole(TenantRole.Admin).id,
userId: id,

View file

@ -44,7 +44,7 @@ export default function applicationRoleRelationRoutes(
async (ctx, next) => {
const { id, applicationId } = ctx.guard.params;
const [totalCount, entities] = await organizations.relations.rolesApps.getEntities(
const [totalCount, entities] = await organizations.relations.appsRoles.getEntities(
OrganizationRoles,
{
organizationId: id,
@ -71,7 +71,7 @@ export default function applicationRoleRelationRoutes(
const { id, applicationId } = ctx.guard.params;
const { organizationRoleIds } = ctx.guard.body;
await organizations.relations.rolesApps.insert(
await organizations.relations.appsRoles.insert(
...organizationRoleIds.map((organizationRoleId) => ({
organizationId: id,
applicationId,
@ -97,7 +97,7 @@ export default function applicationRoleRelationRoutes(
const { id, applicationId } = ctx.guard.params;
const { organizationRoleIds } = ctx.guard.body;
await organizations.relations.rolesApps.replace(id, applicationId, organizationRoleIds);
await organizations.relations.appsRoles.replace(id, applicationId, organizationRoleIds);
ctx.status = 204;
return next();
@ -113,7 +113,7 @@ export default function applicationRoleRelationRoutes(
async (ctx, next) => {
const { id, applicationId, organizationRoleId } = ctx.guard.params;
await organizations.relations.rolesApps.delete({
await organizations.relations.appsRoles.delete({
organizationId: id,
applicationId,
organizationRoleId,

View file

@ -148,7 +148,10 @@
"description": "The role was removed from the application in the organization successfully."
},
"422": {
"description": "The role could not be removed. The role may not exist."
"description": "The application is not associated with the organization."
},
"404": {
"description": "Cannot find the record to delete."
}
}
}

View file

@ -72,7 +72,7 @@ export default function emailDomainRoutes(
`${pathname}/:emailDomain`,
koaGuard({
params: z.object({ ...params, emailDomain: z.string().min(1) }),
status: [204],
status: [204, 404],
}),
async (ctx, next) => {
const { id, emailDomain } = ctx.guard.params;

View file

@ -129,7 +129,7 @@ export default function organizationRoutes<T extends ManagementApiRouter>(
const { id } = ctx.guard.params;
const { userIds, organizationRoleIds } = ctx.guard.body;
await organizations.relations.rolesUsers.insert(
await organizations.relations.usersRoles.insert(
...organizationRoleIds.flatMap((roleId) =>
userIds.map((userId) => ({ organizationId: id, organizationRoleId: roleId, userId }))
)

View file

@ -43,7 +43,7 @@ export default function userRoleRelationRoutes(
async (ctx, next) => {
const { id, userId } = ctx.guard.params;
const [totalCount, entities] = await organizations.relations.rolesUsers.getEntities(
const [totalCount, entities] = await organizations.relations.usersRoles.getEntities(
OrganizationRoles,
{
organizationId: id,
@ -69,7 +69,7 @@ export default function userRoleRelationRoutes(
const { id, userId } = ctx.guard.params;
const { organizationRoleIds } = ctx.guard.body;
await organizations.relations.rolesUsers.insert(
await organizations.relations.usersRoles.insert(
...organizationRoleIds.map((roleId) => ({
organizationId: id,
organizationRoleId: roleId,
@ -93,7 +93,7 @@ export default function userRoleRelationRoutes(
const { id, userId } = ctx.guard.params;
const { organizationRoleIds } = ctx.guard.body;
await organizations.relations.rolesUsers.replace(id, userId, organizationRoleIds);
await organizations.relations.usersRoles.replace(id, userId, organizationRoleIds);
ctx.status = 204;
return next();
@ -109,7 +109,7 @@ export default function userRoleRelationRoutes(
async (ctx, next) => {
const { id, roleId, userId } = ctx.guard.params;
await organizations.relations.rolesUsers.delete({
await organizations.relations.usersRoles.delete({
organizationId: id,
organizationRoleId: roleId,
userId,
@ -130,7 +130,7 @@ export default function userRoleRelationRoutes(
async (ctx, next) => {
const { id, userId } = ctx.guard.params;
const scopes = await organizations.relations.rolesUsers.getUserScopes(id, userId);
const scopes = await organizations.relations.usersRoles.getUserScopes(id, userId);
ctx.body = scopes;
return next();

View file

@ -190,8 +190,11 @@
"204": {
"description": "The role was removed from the user successfully."
},
"422": {
"description": "The user is not a member of the organization."
},
"404": {
"description": "The user is not a member of the organization; or the user does not have the role."
"description": "Cannot find the record to delete."
}
}
}

View file

@ -112,7 +112,7 @@ devFeatureTest.describe('organization application APIs', () => {
);
const response = await organizationApi
.addApplicationRoles(organization.id, '0', [application.id])
.addApplicationRoles(organization.id, application.id, ['0'])
.catch((error: unknown) => error);
assert(response instanceof HTTPError);
expect(response.response.status).toBe(422);