@loomcore/api 0.2.22 → 0.2.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -13,7 +13,7 @@ export class UsersController extends ApiController {
|
|
|
13
13
|
const userSpec = options.userSpec ?? UserSpec;
|
|
14
14
|
const publicUserSpec = options.publicUserSpec ?? PublicUserSpec;
|
|
15
15
|
const userService = options.userService ?? new UserService(database, userSpec);
|
|
16
|
-
super("users", app, userService, usersRouteAuth, "user", userSpec, publicUserSpec);
|
|
16
|
+
super("users", app, userService, options.routeAuth ?? usersRouteAuth, "user", userSpec, publicUserSpec);
|
|
17
17
|
this.userService = userService;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -50,29 +50,19 @@ const isAuthorized = (config) => {
|
|
|
50
50
|
throw new UnauthenticatedError();
|
|
51
51
|
}
|
|
52
52
|
const authConfig = getAuthConfig();
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (isAdmin(userContext)) {
|
|
58
|
-
next();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const method = resolveAuthMethod(req);
|
|
62
|
-
if (!method) {
|
|
63
|
-
throw new UnauthorizedError();
|
|
64
|
-
}
|
|
65
|
-
assertFeatureRequirement(userContext, config[method]);
|
|
53
|
+
const rawPayload = jwt.verify(token, authConfig.clientSecret);
|
|
54
|
+
const userContext = getAuthUserContextSpec().decode(rawPayload);
|
|
55
|
+
req.userContext = userContext;
|
|
56
|
+
if (isAdmin(userContext)) {
|
|
66
57
|
next();
|
|
58
|
+
return;
|
|
67
59
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
throw err;
|
|
72
|
-
}
|
|
73
|
-
console.error(err);
|
|
74
|
-
throw new UnauthenticatedError();
|
|
60
|
+
const method = resolveAuthMethod(req);
|
|
61
|
+
if (!method) {
|
|
62
|
+
throw new UnauthorizedError();
|
|
75
63
|
}
|
|
64
|
+
assertFeatureRequirement(userContext, config[method]);
|
|
65
|
+
next();
|
|
76
66
|
};
|
|
77
67
|
};
|
|
78
68
|
export { isAuthorized };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type IModelSpec, type IQueryOptions, type IUser, type IUserContext } from "@loomcore/common/models";
|
|
1
|
+
import { type IModelSpec, type IPagedResult, type IQueryOptions, type IUser, type IUserContext } from "@loomcore/common/models";
|
|
2
2
|
import type { AppIdType } from "@loomcore/common/types";
|
|
3
3
|
import type { IDatabase } from "../databases/models/index.js";
|
|
4
4
|
import { MultiTenantApiService } from "./multi-tenant-api.service.js";
|
|
@@ -7,6 +7,10 @@ export declare class UserService extends MultiTenantApiService<IUser> {
|
|
|
7
7
|
private isAdmin;
|
|
8
8
|
private assertAdmin;
|
|
9
9
|
private assertSelfOrAdmin;
|
|
10
|
+
getById(userContext: IUserContext, id: AppIdType): Promise<IUser>;
|
|
11
|
+
get(userContext: IUserContext, queryOptions?: IQueryOptions): Promise<IPagedResult<IUser>>;
|
|
12
|
+
getAll(userContext: IUserContext): Promise<IUser[]>;
|
|
13
|
+
getCount(userContext: IUserContext): Promise<number>;
|
|
10
14
|
fullUpdateById(_userContext: IUserContext, _id: AppIdType, _entity: IUser): Promise<IUser>;
|
|
11
15
|
update(userContext: IUserContext, queryObject: IQueryOptions, entity: Partial<IUser>): Promise<IUser[]>;
|
|
12
16
|
batchUpdate(userContext: IUserContext, entities: Partial<IUser>[]): Promise<IUser[]>;
|
|
@@ -23,6 +23,22 @@ export class UserService extends MultiTenantApiService {
|
|
|
23
23
|
throw new UnauthorizedError();
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
async getById(userContext, id) {
|
|
27
|
+
this.assertSelfOrAdmin(userContext, id);
|
|
28
|
+
return super.getById(userContext, id);
|
|
29
|
+
}
|
|
30
|
+
async get(userContext, queryOptions) {
|
|
31
|
+
this.assertAdmin(userContext);
|
|
32
|
+
return super.get(userContext, queryOptions);
|
|
33
|
+
}
|
|
34
|
+
async getAll(userContext) {
|
|
35
|
+
this.assertAdmin(userContext);
|
|
36
|
+
return super.getAll(userContext);
|
|
37
|
+
}
|
|
38
|
+
async getCount(userContext) {
|
|
39
|
+
this.assertAdmin(userContext);
|
|
40
|
+
return super.getCount(userContext);
|
|
41
|
+
}
|
|
26
42
|
async fullUpdateById(_userContext, _id, _entity) {
|
|
27
43
|
throw new ServerError("User full update is not allowed.");
|
|
28
44
|
}
|