22
33namespace Appwrite ;
44
5+ /**
6+ * Helper class to generate role strings for Permission.
7+ */
58class Role
69{
10+ /**
11+ * Grants access to anyone.
12+ *
13+ * This includes authenticated and unauthenticated users.
14+ *
15+ * @return string
16+ */
717 public static function any (): string
818 {
919 return 'any ' ;
1020 }
21+
22+ /**
23+ * Grants access to a specific user by user ID.
24+ *
25+ * You can optionally pass verified or unverified for
26+ * `status` to target specific types of users.
27+ *
28+ * @param string $id
29+ * @param string $status
30+ * @return string
31+ */
1132 public static function user (string $ id , string $ status = "" ): string
1233 {
1334 if (empty ($ status )) {
1435 return "user: $ id " ;
1536 }
1637 return "user: $ id/ $ status " ;
1738 }
39+
40+ /**
41+ * Grants access to any authenticated or anonymous user.
42+ *
43+ * You can optionally pass verified or unverified for
44+ * `status` to target specific types of users.
45+ *
46+ * @param string $status
47+ * @return string
48+ */
1849 public static function users (string $ status = "" ): string
1950 {
2051 if (empty ($ status )) {
2152 return 'users ' ;
2253 }
2354 return "users/ $ status " ;
2455 }
56+
57+ /**
58+ * Grants access to any guest user without a session.
59+ *
60+ * Authenticated users don't have access to this role.
61+ *
62+ * @return string
63+ */
2564 public static function guests (): string
2665 {
2766 return 'guests ' ;
2867 }
68+
69+ /**
70+ * Grants access to a team by team ID.
71+ *
72+ * You can optionally pass a role for `role` to target
73+ * team members with the specified role.
74+ *
75+ * @param string $id
76+ * @param string $role
77+ * @return string
78+ */
2979 public static function team (string $ id , string $ role = "" ): string
3080 {
3181 if (empty ($ role )) {
3282 return "team: $ id " ;
3383 }
3484 return "team: $ id/ $ role " ;
3585 }
86+
87+ /**
88+ * Grants access to a specific member of a team.
89+ *
90+ * When the member is removed from the team, they will
91+ * no longer have access.
92+ *
93+ * @param string $id
94+ * @return string
95+ */
3696 public static function member (string $ id ): string
3797 {
3898 return "member: $ id " ;
3999 }
100+
101+ /**
102+ * Grants access to a user with the specified label.
103+ *
104+ * @param string $name
105+ * @return string
106+ */
107+ public static function label (string $ name ): string
108+ {
109+ return "label: $ name " ;
110+ }
40111}
0 commit comments