feat(server): implement sealed share lifecycle
Signed-off-by: JustMe <mr.toing@outlook.com>
This commit is contained in:
1 parent
e02e024605
commit
42b93ae2d8
45 files changed
+6327
No files matched your search
@@ -0,0 +1,26 @@
|
||||
namespace WebDrop.Core;
|
||||
|
||||
/// <summary>谁能做什么。规则只写在这里,服务和测试都调用它。</summary>
|
||||
public static class ChannelPolicy
|
||||
{
|
||||
public static bool IsOwner(Principal p) => p.Role == Role.Owner;
|
||||
|
||||
public static bool CanRead(Principal p) => p.Role >= Role.Read;
|
||||
|
||||
/// <summary>成员写入需要频道允许上传,且服务端持有写令牌哈希。</summary>
|
||||
public static bool CanWrite(Channel channel, Principal p) =>
|
||||
p.Role == Role.Owner
|
||||
|| (p.Role == Role.Write && channel.Settings.MembersCanUpload && channel.WriteHash is not null);
|
||||
|
||||
public static bool CanDeleteItem(Channel channel, Item item, Principal p)
|
||||
{
|
||||
if (p.Role == Role.Owner) return true;
|
||||
if (p.Role < Role.Read) return false;
|
||||
return channel.Settings.DeletePolicy switch
|
||||
{
|
||||
DeletePolicy.Anyone => true,
|
||||
DeletePolicy.Own => item.AuthorHash.AsSpan().SequenceEqual(p.EndpointHash),
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user