Skip to content

Commit ccddb97

Browse files
Merge pull request #686 from appwrite/feat-role-label
2 parents a05a5b0 + 9c5ab90 commit ccddb97

File tree

27 files changed

+640
-18
lines changed

27 files changed

+640
-18
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,72 @@
11
package {{ sdk.namespace | caseDot }}
22

3+
/**
4+
* Helper class to generate role strings for [Permission].
5+
*/
36
class Role {
47
companion object {
8+
9+
/**
10+
* Grants access to anyone.
11+
*
12+
* This includes authenticated and unauthenticated users.
13+
*/
514
fun any(): String = "any"
615

16+
/**
17+
* Grants access to a specific user by user ID.
18+
*
19+
* You can optionally pass verified or unverified for
20+
* [status] to target specific types of users.
21+
*/
722
fun user(id: String, status: String = ""): String = if(status.isEmpty()) {
823
"user:$id"
924
} else {
1025
"user:$id/$status"
1126
}
1227

28+
/**
29+
* Grants access to any authenticated or anonymous user.
30+
*
31+
* You can optionally pass verified or unverified for
32+
* [status] to target specific types of users.
33+
*/
1334
fun users(status: String = ""): String = if(status.isEmpty()) {
1435
"users"
1536
} else {
1637
"users/$status"
1738
}
1839

40+
/**
41+
* Grants access to any guest user without a session.
42+
*
43+
* Authenticated users don't have access to this role.
44+
*/
1945
fun guests(): String = "guests"
2046

47+
/**
48+
* Grants access to a team by team ID.
49+
*
50+
* You can optionally pass a role for [role] to target
51+
* team members with the specified role.
52+
*/
2153
fun team(id: String, role: String = ""): String = if(role.isEmpty()) {
2254
"team:$id"
2355
} else {
2456
"team:$id/$role"
2557
}
2658

59+
/**
60+
* Grants access to a specific member of a team.
61+
*
62+
* When the member is removed from the team, they will
63+
* no longer have access.
64+
*/
2765
fun member(id: String): String = "member:$id"
66+
67+
/**
68+
* Grants access to a user with the specified label.
69+
*/
70+
fun label(name: String): String = "label:$name"
2871
}
2972
}

templates/dart/lib/role.dart.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,9 @@ class Role {
5858
static String member(String id) {
5959
return 'member:$id';
6060
}
61+
62+
/// Grants access to a user with the specified label.
63+
static String label(String name) {
64+
return 'label:$name';
65+
}
6166
}

templates/dart/test/role_test.dart.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ void main() {
5353
expect(Role.member('custom'), 'member:custom');
5454
});
5555
});
56+
57+
group('label()', () {
58+
test('returns label', () {
59+
expect(Role.label('admin'), 'label:admin');
60+
});
61+
});
5662
}

templates/deno/src/role.ts.twig

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,100 @@
1+
/**
2+
* Helper class to generate role strings for `Permission`.
3+
*/
14
export class Role {
5+
6+
/**
7+
* Grants access to anyone.
8+
*
9+
* This includes authenticated and unauthenticated users.
10+
*
11+
* @returns {string}
12+
*/
213
public static any(): string {
314
return 'any'
415
}
516

17+
/**
18+
* Grants access to a specific user by user ID.
19+
*
20+
* You can optionally pass verified or unverified for
21+
* `status` to target specific types of users.
22+
*
23+
* @param {string} id
24+
* @param {string} status
25+
* @returns {string}
26+
*/
627
public static user(id: string, status: string = ''): string {
7-
if(status === '') {
28+
if (status === '') {
829
return `user:${id}`
930
}
1031
return `user:${id}/${status}`
1132
}
12-
33+
34+
/**
35+
* Grants access to any authenticated or anonymous user.
36+
*
37+
* You can optionally pass verified or unverified for
38+
* `status` to target specific types of users.
39+
*
40+
* @param {string} status
41+
* @returns {string}
42+
*/
1343
public static users(status: string = ''): string {
14-
if(status === '') {
44+
if (status === '') {
1545
return 'users'
1646
}
1747
return `users/${status}`
1848
}
19-
49+
50+
/**
51+
* Grants access to any guest user without a session.
52+
*
53+
* Authenticated users don't have access to this role.
54+
*
55+
* @returns {string}
56+
*/
2057
public static guests(): string {
2158
return 'guests'
2259
}
23-
60+
61+
/**
62+
* Grants access to a team by team ID.
63+
*
64+
* You can optionally pass a role for `role` to target
65+
* team members with the specified role.
66+
*
67+
* @param {string} id
68+
* @param {string} role
69+
* @returns {string}
70+
*/
2471
public static team(id: string, role: string = ''): string {
25-
if(role === '') {
72+
if (role === '') {
2673
return `team:${id}`
2774
}
2875
return `team:${id}/${role}`
2976
}
3077

78+
/**
79+
* Grants access to a specific member of a team.
80+
*
81+
* When the member is removed from the team, they will
82+
* no longer have access.
83+
*
84+
* @param {string} id
85+
* @returns {string}
86+
*/
3187
public static member(id: string): string {
3288
return `member:${id}`
3389
}
90+
91+
/**
92+
* Grants access to a user with the specified label.
93+
*
94+
* @param {string} name
95+
* @returns {string}
96+
*/
97+
public static label(name: string): string {
98+
return `label:${name}`
99+
}
34100
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,92 @@
11
namespace Appwrite
22
{
3+
/// <summary>
4+
/// Helper class to generate role strings for Permission.
5+
/// </summary>
36
public static class Role
47
{
8+
/// <summary>
9+
/// Grants access to anyone.
10+
/// <para>
11+
/// This includes authenticated and unauthenticated users.
12+
/// </para>
13+
/// </summary>
514
public static string Any()
615
{
716
return "any";
817
}
918

19+
/// <summary>
20+
/// Grants access to a specific user by user ID.
21+
/// <para>
22+
/// You can optionally pass verified or unverified for
23+
/// <c>status</c> to target specific types of users.
24+
/// </para>
25+
/// </summary>
1026
public static string User(string id, string status = "")
1127
{
1228
return status == string.Empty
1329
? $"user:{id}"
1430
: $"user:{id}/{status}";
1531
}
1632

33+
/// <summary>
34+
/// Grants access to any authenticated or anonymous user.
35+
/// <para>
36+
/// You can optionally pass verified or unverified for
37+
/// <c>status</c> to target specific types of users.
38+
/// </para>
39+
/// </summary>
1740
public static string Users(string status = "")
1841
{
1942
return status == string.Empty
2043
? "users" :
2144
$"users/{status}";
2245
}
2346

47+
/// <summary>
48+
/// Grants access to any guest user without a session.
49+
/// <para>
50+
/// Authenticated users don't have access to this role.
51+
/// </para>
52+
/// </summary>
2453
public static string Guests()
2554
{
2655
return "guests";
2756
}
2857

58+
/// <summary>
59+
/// Grants access to a team by team ID.
60+
/// <para>
61+
/// You can optionally pass a role for <c>role</c> to target
62+
/// team members with the specified role.
63+
/// </para>
64+
/// </summary>
2965
public static string Team(string id, string role = "")
3066
{
3167
return role == string.Empty
3268
? $"team:{id}"
3369
: $"team:{id}/{role}";
3470
}
3571

72+
/// <summary>
73+
/// Grants access to a specific member of a team.
74+
/// <para>
75+
/// When the member is removed from the team, they will
76+
/// no longer have access.
77+
/// </para>
78+
/// </summary>
3679
public static string Member(string id)
3780
{
3881
return $"member:{id}";
3982
}
83+
84+
/// <summary>
85+
/// Grants access to a user with the specified label.
86+
/// </summary>
87+
public static string Label(string name)
88+
{
89+
return $"label:{name}";
90+
}
4091
}
4192
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,72 @@
11
package {{ sdk.namespace | caseDot }}
22

3+
/**
4+
* Helper class to generate role strings for [Permission].
5+
*/
36
class Role {
47
companion object {
8+
9+
/**
10+
* Grants access to anyone.
11+
*
12+
* This includes authenticated and unauthenticated users.
13+
*/
514
fun any(): String = "any"
615

16+
/**
17+
* Grants access to a specific user by user ID.
18+
*
19+
* You can optionally pass verified or unverified for
20+
* [status] to target specific types of users.
21+
*/
722
fun user(id: String, status: String = ""): String = if(status.isEmpty()) {
823
"user:$id"
924
} else {
1025
"user:$id/$status"
1126
}
1227

28+
/**
29+
* Grants access to any authenticated or anonymous user.
30+
*
31+
* You can optionally pass verified or unverified for
32+
* [status] to target specific types of users.
33+
*/
1334
fun users(status: String = ""): String = if(status.isEmpty()) {
1435
"users"
1536
} else {
1637
"users/$status"
1738
}
1839

40+
/**
41+
* Grants access to any guest user without a session.
42+
*
43+
* Authenticated users don't have access to this role.
44+
*/
1945
fun guests(): String = "guests"
2046

47+
/**
48+
* Grants access to a team by team ID.
49+
*
50+
* You can optionally pass a role for [role] to target
51+
* team members with the specified role.
52+
*/
2153
fun team(id: String, role: String = ""): String = if(role.isEmpty()) {
2254
"team:$id"
2355
} else {
2456
"team:$id/$role"
2557
}
2658

59+
/**
60+
* Grants access to a specific member of a team.
61+
*
62+
* When the member is removed from the team, they will
63+
* no longer have access.
64+
*/
2765
fun member(id: String): String = "member:$id"
66+
67+
/**
68+
* Grants access to a user with the specified label.
69+
*/
70+
fun label(name: String): String = "label:$name"
2871
}
2972
}

0 commit comments

Comments
 (0)