Skip to content

Commit 7d32803

Browse files
committed
feat: add endpoint to retrieve member permissions in organizations
1 parent 5e27e8f commit 7d32803

5 files changed

Lines changed: 48 additions & 0 deletions

File tree

API.MD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ Endpoints follow the pattern `/api/me/{resource}`. All **POST/PATCH** return `Me
243243
| :--- | :--- | :--- | :--- | :--- | :--- |
244244
| **GET** | `/api/orgs/{org}/members` | List all members. | Any Member | N/A | `IEnumerable<OrganizationMemberDto>` |
245245
| **GET** | `/api/orgs/{org}/members/me/role` | Get my Role. | Any Member | N/A | `MemberRoleDto` |
246+
| **GET** | `/api/orgs/{org}/permissions` | Get my permissions. | Any Member | N/A | `OrganizationPermissionsDto` |
246247
| **POST** | `/api/orgs/{org}/members` | Invite/Add member. | Owner/Admin* | `InviteMemberRequestDto` | `MessageResponse` |
247248
| **PATCH** | `/api/orgs/{org}/members/me` | Update my info. | Any Member | `UpdateMemberRequestDto` | `MessageResponse` |
248249
| **DELETE** | `/api/orgs/{org}/members/me` | Leave organization. | Any Member | N/A | `MessageResponse` |

OpenProfileServer/Controllers/User/OrganizationController.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,20 @@ public async Task<ActionResult<ApiResponse<MemberRoleDto>>> GetMyRole(string org
265265
return result.Status ? Ok(result) : StatusCode(403, result);
266266
}
267267

268+
/// <summary>
269+
/// GET /api/orgs/{org}/permissions
270+
/// Returns the current member's permissions in the organization.
271+
/// </summary>
272+
[HttpGet("{org}/permissions")]
273+
public async Task<ActionResult<ApiResponse<OrganizationPermissionsDto>>> GetMyPermissions(string org)
274+
{
275+
var orgId = await ResolveOrgId(org);
276+
if (orgId == null) return NotFound(ApiResponse<MessageResponse>.Failure("Organization not found."));
277+
278+
var result = await _orgService.GetMyPermissionsAsync(GetUserId(), orgId.Value);
279+
return result.Status ? Ok(result) : StatusCode(403, result);
280+
}
281+
268282
[HttpPatch("{org}/members/me")]
269283
public async Task<ActionResult<ApiResponse<MessageResponse>>> UpdateMyMemberDetails(string org, [FromBody] UpdateMemberRequestDto dto)
270284
{

OpenProfileServer/Interfaces/IOrganizationService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public interface IOrganizationService
3838
// === Members (Self & Management by Owner) ===
3939
Task<ApiResponse<IEnumerable<OrganizationMemberDto>>> GetMembersAsync(Guid userId, Guid orgId);
4040
Task<ApiResponse<MemberRoleDto>> GetMyRoleAsync(Guid userId, Guid orgId);
41+
Task<ApiResponse<OrganizationPermissionsDto>> GetMyPermissionsAsync(Guid userId, Guid orgId);
4142
Task<ApiResponse<MessageResponse>> UpdateMyMemberDetailsAsync(Guid userId, Guid orgId, UpdateMemberRequestDto dto);
4243

4344
Task<ApiResponse<MessageResponse>> RemoveMemberAsync(Guid requesterId, Guid orgId, Guid targetUserId);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using OpenProfileServer.Models.Enums;
2+
3+
namespace OpenProfileServer.Models.DTOs.Organization;
4+
5+
public class OrganizationPermissionsDto
6+
{
7+
/// <summary>
8+
/// Indicates if the current member can invite others to the organization.
9+
/// This is true for Owner/Admin, or for Members when AllowMemberInvite setting is enabled.
10+
/// </summary>
11+
public bool CanInvite { get; set; }
12+
13+
/// <summary>
14+
/// The current member's role in the organization.
15+
/// </summary>
16+
public MemberRole Role { get; set; }
17+
}

OpenProfileServer/Services/OrganizationService.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,21 @@ public async Task<ApiResponse<MemberRoleDto>> GetMyRoleAsync(Guid userId, Guid o
496496
});
497497
}
498498

499+
public async Task<ApiResponse<OrganizationPermissionsDto>> GetMyPermissionsAsync(Guid userId, Guid orgId)
500+
{
501+
var (member, settings) = await GetMemberAndSettingsAsync(userId, orgId);
502+
if (member == null) return ApiResponse<OrganizationPermissionsDto>.Failure("Not a member.");
503+
504+
bool canInvite = member.Role == MemberRole.Owner || member.Role == MemberRole.Admin ||
505+
(member.Role == MemberRole.Member && settings != null && settings.AllowMemberInvite);
506+
507+
return ApiResponse<OrganizationPermissionsDto>.Success(new OrganizationPermissionsDto
508+
{
509+
CanInvite = canInvite,
510+
Role = member.Role
511+
});
512+
}
513+
499514
public async Task<ApiResponse<MessageResponse>> UpdateMyMemberDetailsAsync(Guid userId, Guid orgId, UpdateMemberRequestDto dto)
500515
{
501516
var member = await _context.OrganizationMembers.FirstOrDefaultAsync(m => m.OrganizationId == orgId && m.AccountId == userId);

0 commit comments

Comments
 (0)