@communecter/cocolight-api-client 1.0.108 → 1.0.110

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@communecter/cocolight-api-client",
3
- "version": "1.0.108",
3
+ "version": "1.0.110",
4
4
  "description": "Client Axios simplifié pour l'API cocolight",
5
5
  "repository": {
6
6
  "type": "git",
@@ -3793,10 +3793,12 @@ export class BaseEntity<TServerData = any> {
3793
3793
  /**
3794
3794
  * Vérifie si l'utilisateur est administrateur de l'entité.
3795
3795
  *
3796
+ * @param options - Options de vérification.
3797
+ * @param options.checkHierarchy - Si `true`, vérifie également si l'utilisateur est admin via la hiérarchie parent. Par défaut `false`.
3796
3798
  * @returns - `true` si l'utilisateur est administrateur, `false` sinon.
3797
3799
  * @throws {ApiError}
3798
3800
  */
3799
- isAdmin(): boolean {
3801
+ isAdmin(options?: { checkHierarchy?: boolean }): boolean {
3800
3802
  this._checkAccess("vérifier l'administrateur.");
3801
3803
  this._assertEntityType("organizations", "projects", "events");
3802
3804
 
@@ -3806,8 +3808,13 @@ export class BaseEntity<TServerData = any> {
3806
3808
  return true;
3807
3809
  }
3808
3810
 
3809
- // 2. Si pas de lien direct, remonter la hiérarchie parent
3810
- return this._isAdminViaHierarchy();
3811
+ // 2. Si pas de lien direct, remonter la hiérarchie parent (si activé)
3812
+ const checkHierarchy = options?.checkHierarchy ?? false;
3813
+ if (checkHierarchy) {
3814
+ return this._isAdminViaHierarchy();
3815
+ }
3816
+
3817
+ return false;
3811
3818
  }
3812
3819
 
3813
3820
  /**
package/src/api/Event.ts CHANGED
@@ -75,7 +75,7 @@ export class Event extends BaseEntity<EventItemNormalized> {
75
75
  };
76
76
 
77
77
  override _update = async (payload: Record<string, any>): Promise<boolean> => {
78
- if(!this.isAdmin()){
78
+ if(!this.isAdmin({ checkHierarchy: true })){
79
79
  throw new ApiError("Vous n'avez pas les droits pour modifier cet événement", 403);
80
80
  }
81
81
 
package/src/api/User.ts CHANGED
@@ -1067,7 +1067,11 @@ export class User extends BaseEntity<UserItemNormalized> {
1067
1067
  * }
1068
1068
  */
1069
1069
  override isAdmin(): boolean {
1070
- this._validateMemberPreconditions("isAdmin", ["organizations", "projects"]);
1070
+ try {
1071
+ this._validateMemberPreconditions("isAdmin", ["organizations", "projects"]);
1072
+ } catch{
1073
+ return false;
1074
+ }
1071
1075
  const parentLink = this._getParentLinkForUser();
1072
1076
  return this._validateUserLink(parentLink) && parentLink?.isAdmin === true;
1073
1077
  }
@@ -1098,7 +1102,11 @@ export class User extends BaseEntity<UserItemNormalized> {
1098
1102
  * }
1099
1103
  */
1100
1104
  override isMember(): boolean {
1101
- this._validateMemberPreconditions("isMember", ["organizations"]);
1105
+ try {
1106
+ this._validateMemberPreconditions("isMember", ["organizations"]);
1107
+ } catch{
1108
+ return false;
1109
+ }
1102
1110
  const parentLink = this._getParentLinkForUser();
1103
1111
  return this._validateUserLink(parentLink);
1104
1112
  }
@@ -1129,7 +1137,11 @@ export class User extends BaseEntity<UserItemNormalized> {
1129
1137
  * }
1130
1138
  */
1131
1139
  override isContributor(): boolean {
1132
- this._validateMemberPreconditions("isContributor", ["projects"]);
1140
+ try {
1141
+ this._validateMemberPreconditions("isContributor", ["projects"]);
1142
+ } catch{
1143
+ return false;
1144
+ }
1133
1145
  const parentLink = this._getParentLinkForUser();
1134
1146
  return this._validateUserLink(parentLink);
1135
1147
  }
@@ -1160,7 +1172,11 @@ export class User extends BaseEntity<UserItemNormalized> {
1160
1172
  * }
1161
1173
  */
1162
1174
  override isAttendee(): boolean {
1163
- this._validateMemberPreconditions("isAttendee", ["events"]);
1175
+ try {
1176
+ this._validateMemberPreconditions("isAttendee", ["events"]);
1177
+ } catch{
1178
+ return false;
1179
+ }
1164
1180
  const parentLink = this._getParentLinkForUser();
1165
1181
  return this._validateUserLink(parentLink);
1166
1182
  }
@@ -1183,7 +1199,11 @@ export class User extends BaseEntity<UserItemNormalized> {
1183
1199
  * ```
1184
1200
  */
1185
1201
  isInviting(): boolean {
1186
- this._validateMemberPreconditions("isInviting", ["organizations", "projects", "events"]);
1202
+ try {
1203
+ this._validateMemberPreconditions("isInviting", ["organizations", "projects", "events"]);
1204
+ } catch{
1205
+ return false;
1206
+ }
1187
1207
  const parentLink = this._getParentLinkForUser();
1188
1208
  if (!parentLink) return false;
1189
1209
  return parentLink?.isInviting === true;
@@ -1207,7 +1227,11 @@ export class User extends BaseEntity<UserItemNormalized> {
1207
1227
  * ```
1208
1228
  */
1209
1229
  isInvitingAdmin(): boolean {
1210
- this._validateMemberPreconditions("isInvitingAdmin", ["organizations", "projects"]);
1230
+ try {
1231
+ this._validateMemberPreconditions("isInvitingAdmin", ["organizations", "projects"]);
1232
+ } catch{
1233
+ return false;
1234
+ }
1211
1235
  const parentLink = this._getParentLinkForUser();
1212
1236
  if (!parentLink) return false;
1213
1237
  return (parentLink?.isAdminInviting === true || parentLink?.isInviting === true) && parentLink?.isAdmin === true;
@@ -1233,7 +1257,11 @@ export class User extends BaseEntity<UserItemNormalized> {
1233
1257
  * ```
1234
1258
  */
1235
1259
  isAdminPending(): boolean {
1236
- this._validateMemberPreconditions("isAdminPending", ["organizations", "projects"]);
1260
+ try {
1261
+ this._validateMemberPreconditions("isAdminPending", ["organizations", "projects"]);
1262
+ } catch{
1263
+ return false;
1264
+ }
1237
1265
  const parentLink = this._getParentLinkForUser();
1238
1266
  return parentLink?.isAdmin === true && parentLink?.isAdminPending === true;
1239
1267
  }
@@ -1258,7 +1286,11 @@ export class User extends BaseEntity<UserItemNormalized> {
1258
1286
  * ```
1259
1287
  */
1260
1288
  isToBeValidated(): boolean {
1261
- this._validateMemberPreconditions("isToBeValidated", ["organizations", "projects", "events"]);
1289
+ try {
1290
+ this._validateMemberPreconditions("isToBeValidated", ["organizations", "projects", "events"]);
1291
+ } catch{
1292
+ return false;
1293
+ }
1262
1294
  const parentLink = this._getParentLinkForUser();
1263
1295
  return parentLink?.toBeValidated === true;
1264
1296
  }
@@ -1276,10 +1276,14 @@ export declare class BaseEntity<TServerData = any> {
1276
1276
  /**
1277
1277
  * Vérifie si l'utilisateur est administrateur de l'entité.
1278
1278
  *
1279
+ * @param options - Options de vérification.
1280
+ * @param options.checkHierarchy - Si `true`, vérifie également si l'utilisateur est admin via la hiérarchie parent. Par défaut `false`.
1279
1281
  * @returns - `true` si l'utilisateur est administrateur, `false` sinon.
1280
1282
  * @throws {ApiError}
1281
1283
  */
1282
- isAdmin(): boolean;
1284
+ isAdmin(options?: {
1285
+ checkHierarchy?: boolean;
1286
+ }): boolean;
1283
1287
  /**
1284
1288
  * Vérifie si l'utilisateur est soit l'auteur, soit administrateur de l'entité.
1285
1289
  *