Skip to content

Commit

Permalink
Add support for team roles.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Sep 17, 2023
1 parent c03bc7a commit a8f384a
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public interface ITeamMember
/// Gets the user that's part of the team.
/// </summary>
IPartialUser User { get; }

/// <summary>
/// Gets the user's role.
/// </summary>
TeamMemberRole Role { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// TeamMemberRole.cs
//
// Author:
// Jarl Gullberg <jarl.gullberg@gmail.com>
//
// Copyright (c) Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

namespace Remora.Discord.API.Abstractions.Objects;

/// <summary>
/// Enumerates various roles a team member can have.
/// </summary>
public enum TeamMemberRole
{
/// <summary>
/// Owners are the most permissible role, and can take destructive, irreversible actions like deleting team-owned
/// apps or the team itself. Teams are limited to 1 owner.
/// </summary>
Owner,

/// <summary>
/// Admins have similar access as owners, except they cannot take destructive actions on the team or team-owned
/// apps.
/// </summary>
Admin,

/// <summary>
/// Developers can access information about team-owned apps, like the client secret or public key. They can also
/// take limited actions on team-owned apps, like configuring interaction endpoints or resetting the bot token.
/// Members with the Developer role *cannot* manage the team or its members, or take destructive actions on
/// team-owned apps.
/// </summary>
Developer,

/// <summary>
/// Read-only members can access information about a team and any team-owned apps. Some examples include getting the
/// IDs of applications and exporting payout records.
/// </summary>
ReadOnly
}
3 changes: 2 additions & 1 deletion Backend/Remora.Discord.API/API/Objects/Teams/TeamMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ public record TeamMember
MembershipState MembershipState,
IReadOnlyList<string> Permissions,
Snowflake TeamID,
IPartialUser User
IPartialUser User,
TeamMemberRole Role
) : ITeamMember;
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,8 @@ private static JsonSerializerOptions AddOAuth2ObjectConverters(this JsonSerializ
private static JsonSerializerOptions AddTeamObjectConverters(this JsonSerializerOptions options)
{
options.AddDataObjectConverter<ITeam, Team>();
options.AddDataObjectConverter<ITeamMember, TeamMember>();
options.AddDataObjectConverter<ITeamMember, TeamMember>()
.WithPropertyConverter(m => m.Role, new StringEnumConverter<TeamMemberRole>(new SnakeCaseNamingPolicy()));

return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"discriminator": "9999",
"id": "999999999999999999",
"username": "none"
}
},
"role": "read_only"
}
],
"name": "none",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"discriminator": "9999",
"id": "999999999999999999",
"username": "none"
}
},
"role": "read_only"
}
],
"name": "none",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"global_name": "none",
"id": "999999999999999999",
"username": "none"
}
},
"role": "read_only"
}
],
"name": "none",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"global_name": "none",
"id": "999999999999999999",
"username": "none"
}
},
"role": "read_only"
}
],
"name": "none",
Expand Down
3 changes: 2 additions & 1 deletion Tests/Remora.Discord.Tests/Samples/Objects/TEAM/TEAM.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"discriminator": "9999",
"id": "999999999999999999",
"avatar": "68b329da9893e34099c7d8ad5cb9c940"
}
},
"role": "read_only"
}
],
"name": "none",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"discriminator": "9999",
"id": "999999999999999999",
"avatar": "68b329da9893e34099c7d8ad5cb9c940"
}
},
"role": "read_only"
}
],
"name": "none",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"discriminator": "9999",
"id": "999999999999999999",
"avatar": "68b329da9893e34099c7d8ad5cb9c940"
}
},
"role": "read_only"
}

0 comments on commit a8f384a

Please sign in to comment.