mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 00:22:50 -05:00
Implemented Custom role and permissions (#1057)
* Implemented Custom role and permissions * Converted permissions columns to a json blob * Code review fixes for Permissions * sql build fix * Update Permissions.cs * formatting * Update IOrganizationService.cs * reworked a conditional * built out tests for relevant organization service methods * removed unused usings * fixed a broken test and a bad empty string init * removed 'Attribute' from some attribute instances
This commit is contained in:
@ -20,6 +20,7 @@ using Microsoft.Azure.Storage;
|
||||
using Microsoft.Azure.Storage.Blob;
|
||||
using Bit.Core.Models.Table;
|
||||
using IdentityModel;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Bit.Core.Utilities
|
||||
{
|
||||
@ -730,6 +731,62 @@ namespace Bit.Core.Utilities
|
||||
claims.Add(new KeyValuePair<string, string>("orguser", org.Id.ToString()));
|
||||
}
|
||||
break;
|
||||
case Enums.OrganizationUserType.Custom:
|
||||
foreach (var org in group)
|
||||
{
|
||||
claims.Add(new KeyValuePair<string, string>("orgcustom", org.Id.ToString()));
|
||||
|
||||
if (org.Permissions.AccessBusinessPortal)
|
||||
{
|
||||
claims.Add(new KeyValuePair<string, string>("accessbusinessportal", org.Id.ToString()));
|
||||
}
|
||||
|
||||
if (org.Permissions.AccessEventLogs)
|
||||
{
|
||||
claims.Add(new KeyValuePair<string, string>("accesseventlogs", org.Id.ToString()));
|
||||
}
|
||||
|
||||
if (org.Permissions.AccessImportExport)
|
||||
{
|
||||
claims.Add(new KeyValuePair<string, string>("accessimportexport", org.Id.ToString()));
|
||||
}
|
||||
|
||||
if (org.Permissions.AccessReports)
|
||||
{
|
||||
claims.Add(new KeyValuePair<string, string>("accessreports", org.Id.ToString()));
|
||||
}
|
||||
|
||||
if (org.Permissions.ManageAllCollections)
|
||||
{
|
||||
claims.Add(new KeyValuePair<string, string>("manageallcollections", org.Id.ToString()));
|
||||
}
|
||||
|
||||
if (org.Permissions.ManageAssignedCollections)
|
||||
{
|
||||
claims.Add(new KeyValuePair<string, string>("manageassignedcollections", org.Id.ToString()));
|
||||
}
|
||||
|
||||
if (org.Permissions.ManageGroups)
|
||||
{
|
||||
claims.Add(new KeyValuePair<string, string>("managegroups", org.Id.ToString()));
|
||||
}
|
||||
|
||||
if (org.Permissions.ManagePolicies)
|
||||
{
|
||||
claims.Add(new KeyValuePair<string, string>("managepolicies", org.Id.ToString()));
|
||||
}
|
||||
|
||||
if (org.Permissions.ManageSso)
|
||||
{
|
||||
claims.Add(new KeyValuePair<string, string>("managesso", org.Id.ToString()));
|
||||
}
|
||||
|
||||
if (org.Permissions.ManageUsers)
|
||||
{
|
||||
claims.Add(new KeyValuePair<string, string>("manageusers", org.Id.ToString()));
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -737,5 +794,20 @@ namespace Bit.Core.Utilities
|
||||
}
|
||||
return claims;
|
||||
}
|
||||
|
||||
public static T LoadClassFromJsonData<T>(string jsonData) where T : new()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(jsonData))
|
||||
{
|
||||
return new T();
|
||||
}
|
||||
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||
};
|
||||
|
||||
return System.Text.Json.JsonSerializer.Deserialize<T>(jsonData, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user