Skip to content

Add label method to Role helper #686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions templates/android/library/src/main/java/io/appwrite/Role.kt.twig
Original file line number Diff line number Diff line change
@@ -1,29 +1,72 @@
package {{ sdk.namespace | caseDot }}

/**
* Helper class to generate role strings for [Permission].
*/
class Role {
companion object {

/**
* Grants access to anyone.
*
* This includes authenticated and unauthenticated users.
*/
fun any(): String = "any"

/**
* Grants access to a specific user by user ID.
*
* You can optionally pass verified or unverified for
* [status] to target specific types of users.
*/
fun user(id: String, status: String = ""): String = if(status.isEmpty()) {
"user:$id"
} else {
"user:$id/$status"
}

/**
* Grants access to any authenticated or anonymous user.
*
* You can optionally pass verified or unverified for
* [status] to target specific types of users.
*/
fun users(status: String = ""): String = if(status.isEmpty()) {
"users"
} else {
"users/$status"
}

/**
* Grants access to any guest user without a session.
*
* Authenticated users don't have access to this role.
*/
fun guests(): String = "guests"

/**
* Grants access to a team by team ID.
*
* You can optionally pass a role for [role] to target
* team members with the specified role.
*/
fun team(id: String, role: String = ""): String = if(role.isEmpty()) {
"team:$id"
} else {
"team:$id/$role"
}

/**
* Grants access to a specific member of a team.
*
* When the member is removed from the team, they will
* no longer have access.
*/
fun member(id: String): String = "member:$id"

/**
* Grants access to a user with the specified label.
*/
fun label(name: String): String = "label:$name"
}
}
5 changes: 5 additions & 0 deletions templates/dart/lib/role.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ class Role {
static String member(String id) {
return 'member:$id';
}

/// Grants access to a user with the specified label.
static String label(String name) {
return 'label:$name';
}
}
6 changes: 6 additions & 0 deletions templates/dart/test/role_test.dart.twig
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ void main() {
expect(Role.member('custom'), 'member:custom');
});
});

group('label()', () {
test('returns label', () {
expect(Role.label('admin'), 'label:admin');
});
});
}
78 changes: 72 additions & 6 deletions templates/deno/src/role.ts.twig
Original file line number Diff line number Diff line change
@@ -1,34 +1,100 @@
/**
* Helper class to generate role strings for `Permission`.
*/
export class Role {

/**
* Grants access to anyone.
*
* This includes authenticated and unauthenticated users.
*
* @returns {string}
*/
public static any(): string {
return 'any'
}

/**
* Grants access to a specific user by user ID.
*
* You can optionally pass verified or unverified for
* `status` to target specific types of users.
*
* @param {string} id
* @param {string} status
* @returns {string}
*/
public static user(id: string, status: string = ''): string {
if(status === '') {
if (status === '') {
return `user:${id}`
}
return `user:${id}/${status}`
}


/**
* Grants access to any authenticated or anonymous user.
*
* You can optionally pass verified or unverified for
* `status` to target specific types of users.
*
* @param {string} status
* @returns {string}
*/
public static users(status: string = ''): string {
if(status === '') {
if (status === '') {
return 'users'
}
return `users/${status}`
}


/**
* Grants access to any guest user without a session.
*
* Authenticated users don't have access to this role.
*
* @returns {string}
*/
public static guests(): string {
return 'guests'
}


/**
* Grants access to a team by team ID.
*
* You can optionally pass a role for `role` to target
* team members with the specified role.
*
* @param {string} id
* @param {string} role
* @returns {string}
*/
public static team(id: string, role: string = ''): string {
if(role === '') {
if (role === '') {
return `team:${id}`
}
return `team:${id}/${role}`
}

/**
* Grants access to a specific member of a team.
*
* When the member is removed from the team, they will
* no longer have access.
*
* @param {string} id
* @returns {string}
*/
public static member(id: string): string {
return `member:${id}`
}

/**
* Grants access to a user with the specified label.
*
* @param {string} name
* @returns {string}
*/
public static label(name: string): string {
return `label:${name}`
}
}
51 changes: 51 additions & 0 deletions templates/dotnet/src/Appwrite/Role.cs.twig
Original file line number Diff line number Diff line change
@@ -1,41 +1,92 @@
namespace Appwrite
{
/// <summary>
/// Helper class to generate role strings for Permission.
/// </summary>
public static class Role
{
/// <summary>
/// Grants access to anyone.
/// <para>
/// This includes authenticated and unauthenticated users.
/// </para>
/// </summary>
public static string Any()
{
return "any";
}

/// <summary>
/// Grants access to a specific user by user ID.
/// <para>
/// You can optionally pass verified or unverified for
/// <c>status</c> to target specific types of users.
/// </para>
/// </summary>
public static string User(string id, string status = "")
{
return status == string.Empty
? $"user:{id}"
: $"user:{id}/{status}";
}

/// <summary>
/// Grants access to any authenticated or anonymous user.
/// <para>
/// You can optionally pass verified or unverified for
/// <c>status</c> to target specific types of users.
/// </para>
/// </summary>
public static string Users(string status = "")
{
return status == string.Empty
? "users" :
$"users/{status}";
}

/// <summary>
/// Grants access to any guest user without a session.
/// <para>
/// Authenticated users don't have access to this role.
/// </para>
/// </summary>
public static string Guests()
{
return "guests";
}

/// <summary>
/// Grants access to a team by team ID.
/// <para>
/// You can optionally pass a role for <c>role</c> to target
/// team members with the specified role.
/// </para>
/// </summary>
public static string Team(string id, string role = "")
{
return role == string.Empty
? $"team:{id}"
: $"team:{id}/{role}";
}

/// <summary>
/// Grants access to a specific member of a team.
/// <para>
/// When the member is removed from the team, they will
/// no longer have access.
/// </para>
/// </summary>
public static string Member(string id)
{
return $"member:{id}";
}

/// <summary>
/// Grants access to a user with the specified label.
/// </summary>
public static string Label(string name)
{
return $"label:{name}";
}
}
}
43 changes: 43 additions & 0 deletions templates/kotlin/src/main/kotlin/io/appwrite/Role.kt.twig
Original file line number Diff line number Diff line change
@@ -1,29 +1,72 @@
package {{ sdk.namespace | caseDot }}

/**
* Helper class to generate role strings for [Permission].
*/
class Role {
companion object {

/**
* Grants access to anyone.
*
* This includes authenticated and unauthenticated users.
*/
fun any(): String = "any"

/**
* Grants access to a specific user by user ID.
*
* You can optionally pass verified or unverified for
* [status] to target specific types of users.
*/
fun user(id: String, status: String = ""): String = if(status.isEmpty()) {
"user:$id"
} else {
"user:$id/$status"
}

/**
* Grants access to any authenticated or anonymous user.
*
* You can optionally pass verified or unverified for
* [status] to target specific types of users.
*/
fun users(status: String = ""): String = if(status.isEmpty()) {
"users"
} else {
"users/$status"
}

/**
* Grants access to any guest user without a session.
*
* Authenticated users don't have access to this role.
*/
fun guests(): String = "guests"

/**
* Grants access to a team by team ID.
*
* You can optionally pass a role for [role] to target
* team members with the specified role.
*/
fun team(id: String, role: String = ""): String = if(role.isEmpty()) {
"team:$id"
} else {
"team:$id/$role"
}

/**
* Grants access to a specific member of a team.
*
* When the member is removed from the team, they will
* no longer have access.
*/
fun member(id: String): String = "member:$id"

/**
* Grants access to a user with the specified label.
*/
fun label(name: String): String = "label:$name"
}
}
Loading