Skip to content

Commit

Permalink
fix: Merge branch 'main' into deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Aug 24, 2023
2 parents c76c01c + 78a1177 commit 5d959cc
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
84 changes: 69 additions & 15 deletions packages/restapi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3318,9 +3318,11 @@ const response = await PushAPI.chat.createGroup({
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'roleId': '19924'
'guildRoleId': '19924'
}
}
]
Expand All @@ -3343,9 +3345,11 @@ const response = await PushAPI.chat.createGroup({
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'roleId': '19924'
'guildRoleId': '19924'
}
}
]
Expand Down Expand Up @@ -3459,15 +3463,37 @@ Explanation:

#### GUILD Conditions

GUILD conditions require both guildID and guildRoleId or guildRoleAction.
Sample GUILD condition schema
<pre>
{
"type": "GUILD",
"category": "guildRoles",
"subcategory": <Role Type>,
"data": {
"guildId": <Guild ID>,
"guildRoleId": <Specific Role ID>
}
}
</pre>

- **Working**:
Guild ID Validation: The function first checks for the presence of the guildId.
API Call: On confirming its presence, the function then fetches guild data from a specific API endpoint to ascertain the guild's validity.
Role and Action Checks: After validating the guild:
The function checks for the presence of guildRoleId or guildRoleAction. At least one must be specified.
If guildRoleId is given, its legitimacy is cross-verified with the guild's roles.
For guildRoleAction, the function ensures its value is strictly "all" or "any".

Fields:
type:
Always set to: "GUILD"
category:
Always set to: "guildRoles"
subcategory:
Role type classification.
Values:
specificRole: For a singular role.
allRoles: Pertaining to all roles in the guild.
anyRole: Referring to any role within the guild.
data:
guildId: Unique identifier of a guild.
guildRoleId: Role ID within the guild. (Required only for the specificRole subcategory.)
Usage:
This structure governs user permissions within a guild. The subcategory dictates the manner of role-based operations, from checking permissions of a single role (specificRole) to broad checks across any or all roles (anyRole, allRoles).

<details>
<summary><b>Expected response (create group)</b></summary>
Expand Down Expand Up @@ -3595,6 +3621,8 @@ For guildRoleAction, the function ensures its value is strictly "all" or "any".
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'guildRoleId': '19924'
Expand Down Expand Up @@ -3628,16 +3656,19 @@ For guildRoleAction, the function ensures its value is strictly "all" or "any".
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'guildRoleId': '19924'
}
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'anyRole',
'data': {
'guildId': '13468',
'guildRoleAction': 'all/any'
'guildId': '13468'
}
}
]
Expand Down Expand Up @@ -3700,6 +3731,8 @@ Allowed Options (params with _ are mandatory)
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'guildRoleId': '19924'
Expand Down Expand Up @@ -3737,6 +3770,8 @@ Allowed Options (params with _ are mandatory)
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'guildRoleId': '19924'
Expand Down Expand Up @@ -3818,6 +3853,8 @@ const response = await PushAPI.chat.updateGroup({
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'guidlRoleId': '19924'
Expand All @@ -3843,6 +3880,8 @@ const response = await PushAPI.chat.updateGroup({
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'guildRoleId': '19924'
Expand Down Expand Up @@ -4018,6 +4057,8 @@ Allowed Options (params with _ are mandatory)
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'guildRoleId': '19924'
Expand All @@ -4043,6 +4084,8 @@ Allowed Options (params with _ are mandatory)
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'guildRoleId': '19924'
Expand Down Expand Up @@ -4717,6 +4760,8 @@ const response = await PushAPI.space.create({
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'guildRoleId': '19924'
Expand Down Expand Up @@ -4894,6 +4939,8 @@ export interface Rules {
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'guildRoleId': '19924'
Expand Down Expand Up @@ -4958,6 +5005,8 @@ Allowed Options (params with _ are mandatory)
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'guildRoleId': '19924'
Expand Down Expand Up @@ -5054,9 +5103,10 @@ const response = await PushAPI.space.update({
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'allRoles',
'data': {
'guildId': '13468',
'roleId': '19924'
'guildId': '13468'
}
}
]
Expand All @@ -5079,9 +5129,11 @@ const response = await PushAPI.space.update({
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'roleId': '19924'
'guildRoleId': '19924'
}
}
]
Expand Down Expand Up @@ -5222,9 +5274,11 @@ Allowed Options (params with _ are mandatory)
},
{
'type': 'GUILD',
'category': 'guildRoles',
'subcategory': 'specificRole',
'data': {
'guildId': '13468',
'roleId': '19924'
'guildRoleId': '19924'
}
},
{
Expand Down
6 changes: 5 additions & 1 deletion packages/restapi/src/lib/chat/getGroupAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from 'axios';
import { getAPIBaseUrls } from '../helpers';
import Constants, { ENV } from '../constants';
import { GroupAccess } from '../types';
import { getUserDID } from './helpers';

/**
* GET /v1/chat/groups/:chatId/access/:did
Expand All @@ -22,12 +23,15 @@ export const getGroupAccess = async (
if (chatId == null || chatId.length === 0) {
throw new Error(`chatId cannot be null or empty`);
}

if (did == null || did.length === 0) {
throw new Error(`did cannot be null or empty`);
}

const user = await getUserDID(did, env);

const API_BASE_URL = getAPIBaseUrls(env);
const requestUrl = `${API_BASE_URL}/v1/chat/groups/${chatId}/access/${did}`;
const requestUrl = `${API_BASE_URL}/v1/chat/groups/${chatId}/access/${user}`;
return axios
.get(requestUrl)
.then((response) => {
Expand Down
1 change: 0 additions & 1 deletion packages/restapi/src/lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ export type Data = {
decimals?: number;
guildId?: string;
guildRoleId?: string;
guildRoleAction?: 'all' | 'any';
url?: string;
comparison?: '>' | '<' | '>=' | '<=' | '==' | '!=';
};
Expand Down

0 comments on commit 5d959cc

Please sign in to comment.