@selfcommunity/react-core 1.4.1 → 1.5.0

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.
@@ -1,8 +1,16 @@
1
1
  import { SCGroupType, SCUserType } from '@selfcommunity/types';
2
2
  /**
3
- * Check if user is an admin of the group
3
+ * Check if the current user is an admin of the group (creator, manager or elected admin).
4
+ * Relies on the `can_manage` flag computed by the backend for the requesting user.
4
5
  * @param group
5
- * @param user
6
+ * @param user the current user
6
7
  * @returns boolean
7
8
  */
8
9
  export declare function isGroupAdmin(group: SCGroupType, user: SCUserType): boolean;
10
+ /**
11
+ * Check if user is the creator of the group
12
+ * @param group
13
+ * @param user
14
+ * @returns boolean
15
+ */
16
+ export declare function isGroupCreator(group: SCGroupType, user: SCUserType): boolean;
@@ -1,14 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isGroupAdmin = void 0;
3
+ exports.isGroupCreator = exports.isGroupAdmin = void 0;
4
4
  /**
5
- * Check if user is an admin of the group
5
+ * Check if the current user is an admin of the group (creator, manager or elected admin).
6
+ * Relies on the `can_manage` flag computed by the backend for the requesting user.
6
7
  * @param group
7
- * @param user
8
+ * @param user the current user
8
9
  * @returns boolean
9
10
  */
10
11
  function isGroupAdmin(group, user) {
11
- var _a;
12
- return Boolean(group && user && ((_a = group.managed_by) === null || _a === void 0 ? void 0 : _a.id) === user.id);
12
+ return Boolean(group && user && group.can_manage);
13
13
  }
14
14
  exports.isGroupAdmin = isGroupAdmin;
15
+ /**
16
+ * Check if user is the creator of the group
17
+ * @param group
18
+ * @param user
19
+ * @returns boolean
20
+ */
21
+ function isGroupCreator(group, user) {
22
+ var _a;
23
+ return Boolean(group && user && ((_a = group.created_by) === null || _a === void 0 ? void 0 : _a.id) === user.id);
24
+ }
25
+ exports.isGroupCreator = isGroupCreator;
@@ -1,8 +1,16 @@
1
1
  import { SCGroupType, SCUserType } from '@selfcommunity/types';
2
2
  /**
3
- * Check if user is an admin of the group
3
+ * Check if the current user is an admin of the group (creator, manager or elected admin).
4
+ * Relies on the `can_manage` flag computed by the backend for the requesting user.
4
5
  * @param group
5
- * @param user
6
+ * @param user the current user
6
7
  * @returns boolean
7
8
  */
8
9
  export declare function isGroupAdmin(group: SCGroupType, user: SCUserType): boolean;
10
+ /**
11
+ * Check if user is the creator of the group
12
+ * @param group
13
+ * @param user
14
+ * @returns boolean
15
+ */
16
+ export declare function isGroupCreator(group: SCGroupType, user: SCUserType): boolean;
@@ -1,10 +1,20 @@
1
1
  /**
2
- * Check if user is an admin of the group
2
+ * Check if the current user is an admin of the group (creator, manager or elected admin).
3
+ * Relies on the `can_manage` flag computed by the backend for the requesting user.
3
4
  * @param group
4
- * @param user
5
+ * @param user the current user
5
6
  * @returns boolean
6
7
  */
7
8
  export function isGroupAdmin(group, user) {
9
+ return Boolean(group && user && group.can_manage);
10
+ }
11
+ /**
12
+ * Check if user is the creator of the group
13
+ * @param group
14
+ * @param user
15
+ * @returns boolean
16
+ */
17
+ export function isGroupCreator(group, user) {
8
18
  var _a;
9
- return Boolean(group && user && ((_a = group.managed_by) === null || _a === void 0 ? void 0 : _a.id) === user.id);
19
+ return Boolean(group && user && ((_a = group.created_by) === null || _a === void 0 ? void 0 : _a.id) === user.id);
10
20
  }