@punks/backend-entity-manager 0.0.194 → 0.0.196
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.
- package/dist/cjs/index.js +15 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/integrations/repository/typeorm/permissionsChecker.d.ts +4 -0
- package/dist/cjs/types/integrations/repository/typeorm/queryBuilder.d.ts +2 -0
- package/dist/esm/index.js +15 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/integrations/repository/typeorm/permissionsChecker.d.ts +4 -0
- package/dist/esm/types/integrations/repository/typeorm/queryBuilder.d.ts +2 -0
- package/dist/index.d.ts +5 -0
- package/package.json +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -2835,11 +2835,18 @@ class QueryClauseBuilder {
|
|
|
2835
2835
|
}
|
|
2836
2836
|
}
|
|
2837
2837
|
|
|
2838
|
+
class PermissionsChecker {
|
|
2839
|
+
hasPermission(context, permissions) {
|
|
2840
|
+
return (context.userPermissions?.some((p) => permissions.includes(p.uid)) ?? false);
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
|
|
2838
2844
|
class TypeOrmQueryBuilder extends QueryBuilderBase {
|
|
2839
2845
|
constructor(services) {
|
|
2840
2846
|
super();
|
|
2841
2847
|
this.services = services;
|
|
2842
2848
|
this.clause = new QueryClauseBuilder();
|
|
2849
|
+
this.permissions = new PermissionsChecker();
|
|
2843
2850
|
}
|
|
2844
2851
|
async get(id, context) {
|
|
2845
2852
|
return await this.getRepository().get(id, {
|
|
@@ -22749,26 +22756,28 @@ let AuthenticationMiddleware = class AuthenticationMiddleware {
|
|
|
22749
22756
|
const organizationalUnits = user
|
|
22750
22757
|
? await this.getUserOrganizationalUnits(user)
|
|
22751
22758
|
: [];
|
|
22752
|
-
|
|
22759
|
+
const authData = {
|
|
22753
22760
|
user,
|
|
22754
22761
|
roles,
|
|
22755
22762
|
permissions,
|
|
22756
22763
|
organizationalUnits,
|
|
22757
22764
|
};
|
|
22758
|
-
await this.postProcessContext(
|
|
22765
|
+
req.auth = await this.postProcessContext(authData);
|
|
22759
22766
|
}
|
|
22760
22767
|
}
|
|
22761
22768
|
next();
|
|
22762
22769
|
}
|
|
22763
|
-
async postProcessContext(
|
|
22770
|
+
async postProcessContext(authData) {
|
|
22771
|
+
let processedAuth = authData;
|
|
22764
22772
|
const authenticationMiddlewares = this.getAuthenticationMiddlewares();
|
|
22765
22773
|
for (const middleware of authenticationMiddlewares) {
|
|
22766
|
-
const additionalProps = await middleware.processContext(
|
|
22767
|
-
|
|
22768
|
-
...
|
|
22774
|
+
const additionalProps = await middleware.processContext(authData);
|
|
22775
|
+
processedAuth = {
|
|
22776
|
+
...authData,
|
|
22769
22777
|
...additionalProps,
|
|
22770
22778
|
};
|
|
22771
22779
|
}
|
|
22780
|
+
return processedAuth;
|
|
22772
22781
|
}
|
|
22773
22782
|
getAuthenticationMiddlewares() {
|
|
22774
22783
|
return this.registry
|