Skip to content
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
4 changes: 2 additions & 2 deletions FamilyVaultServer/Models/FamilyGroupMember.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FamilyVaultServer.Services.PrivMx.Models;
using FamilyVaultServer.Utils;
using System.Text.Json.Serialization;

namespace FamilyVaultServer.Models.Responses
Expand All @@ -21,8 +22,7 @@ public static FamilyGroupMember FromPrivMxContextUser(PrivMxContextUser user)
Firstname = userIdSplitted.First(),
Surname = userIdSplitted.Last(),
PublicKey = user.PubKey,
// TODO: Ustawienie odpowiedniego PermissionGroup
PermissionGroup = PermissionGroup.Member
PermissionGroup = AclToPermissionGroupMapper.Map(user.Acl)
};
}
}
Expand Down
1 change: 1 addition & 0 deletions FamilyVaultServer/Models/PermissionGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public enum PermissionGroup
{
Unknown = -1,
Guardian = 0,
Member = 1,
Guest = 2,
Expand Down
11 changes: 11 additions & 0 deletions FamilyVaultServer/Services/PrivMx/Models/PrivMxAcl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace FamilyVaultServer.Services.PrivMx.Models
{
public record class PrivMxAcl(string Type, string Object, string? Permission = null)
{
public override string ToString()
{
var separator = Permission is not null ? "/" : "";
return $"{Type} {Object}{separator}{Permission}";
}
}
}
31 changes: 31 additions & 0 deletions FamilyVaultServer/Utils/AclToPermissionGroupMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using FamilyVaultServer.Models;
using FamilyVaultServer.Services.PrivMx.Models;

namespace FamilyVaultServer.Utils
{
public static class AclToPermissionGroupMapper
{
public static PermissionGroup Map(string acl)
{
if (HasAllRequiredAcls(acl, PermissionGroupAcls.guardianAcl))
{
return PermissionGroup.Guardian;
}

if (HasAllRequiredAcls(acl, PermissionGroupAcls.memberAcl))
{
return PermissionGroup.Member;
}

if (HasAllRequiredAcls(acl, PermissionGroupAcls.guestAcl))
{
return PermissionGroup.Guest;
}

return PermissionGroup.Unknown;
}

private static bool HasAllRequiredAcls(string acl, List<PrivMxAcl> acls) =>
acls.All((requiredAcl) => acl.Contains(requiredAcl.ToString()));
}
}
40 changes: 40 additions & 0 deletions FamilyVaultServer/Utils/PermissionGroupAcls.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using FamilyVaultServer.Services.PrivMx.Models;

namespace FamilyVaultServer.Utils
{
public static class PermissionGroupAcls
{
public static readonly List<PrivMxAcl> guardianAcl = [
new PrivMxAcl("ALLOW", "ALL")
];

public static readonly List<PrivMxAcl> memberAcl = [
new PrivMxAcl("ALLOW", "thread", "READ"),
new PrivMxAcl("ALLOW", "thread", "threadCreate"),
new PrivMxAcl("ALLOW", "thread", "threadUpdate"),
new PrivMxAcl("ALLOW", "thread", "threadMessageSend"),
new PrivMxAcl("ALLOW", "thread", "threadMessageDelete"),
new PrivMxAcl("ALLOW", "thread", "threadDelete"),
new PrivMxAcl("ALLOW", "store", "READ"),
new PrivMxAcl("ALLOW", "store", "storeCreate"),
new PrivMxAcl("ALLOW", "store", "storeFileCreate"),
new PrivMxAcl("ALLOW", "store", "storeFileWrite"),
new PrivMxAcl("ALLOW", "store", "storeFileDelete"),
new PrivMxAcl("ALLOW", "inbox", "READ"),
new PrivMxAcl("ALLOW", "stream", "READ")
];

public static readonly List<PrivMxAcl> guestAcl = [
new PrivMxAcl("ALLOW", "thread", "READ"),
new PrivMxAcl("ALLOW", "thread", "threadCreate"),
new PrivMxAcl("ALLOW", "thread", "threadMessageSend"),
new PrivMxAcl("ALLOW", "thread", "threadMessageDelete"),
new PrivMxAcl("ALLOW", "store", "READ"),
new PrivMxAcl("ALLOW", "store", "storeCreate"),
new PrivMxAcl("ALLOW", "store", "storeFileCreate"),
new PrivMxAcl("ALLOW", "store", "storeFileDelete"),
new PrivMxAcl("ALLOW", "inbox", "READ"),
new PrivMxAcl("ALLOW", "stream", "READ")
];
}
}
13 changes: 10 additions & 3 deletions FamilyVaultServer/Utils/PermissionGroupToAclMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FamilyVaultServer.Models;
using FamilyVaultServer.Services.PrivMx.Models;

namespace FamilyVaultServer.Utils
{
Expand All @@ -8,11 +9,17 @@ public static string Map(PermissionGroup permissionGroup)
{
return permissionGroup switch
{
PermissionGroup.Guardian => "ALLOW ALL",
PermissionGroup.Member => "ALLOW ALL",
PermissionGroup.Guest => "ALLOW ALL",
PermissionGroup.Guardian => AclListToString(PermissionGroupAcls.guardianAcl),

PermissionGroup.Member => AclListToString(PermissionGroupAcls.memberAcl),

PermissionGroup.Guest => AclListToString(PermissionGroupAcls.guestAcl),

_ => throw new ArgumentException("Provided not valid PermissionGroup"),
};
}

private static string AclListToString(List<PrivMxAcl> acls) =>
string.Join("\n", acls.Select((acl) => acl.ToString()));
}
}