internal PermissionOverwrite(PermissionTarget targetType, ulong targetId, uint allow, uint deny) { TargetType = targetType; TargetId = targetId; Permissions = new DualChannelPermissions(allow, deny); Permissions.Lock(); }
internal void Update(APIChannel model) { if (!IsPrivate && model.Name != null) { Name = model.Name; } if (model.Type != null) { Type = model.Type; } if (model.Position != null) { Position = model.Position.Value; } if (model.Topic != null) { Topic = model.Topic; } if (model.Recipient != null) { Recipient.Update(model.Recipient); Name = $"@{Recipient}"; } if (model.PermissionOverwrites != null) { _permissionOverwrites = model.PermissionOverwrites .Select(x => new PermissionOverwrite(PermissionTarget.FromString(x.Type), x.Id, x.Allow, x.Deny)) .ToDictionary(x => x.TargetId); UpdatePermissions(); } }
private async Task RemoveChannelPermissions(Channel channel, string userOrRoleId, PermissionTarget targetType) { try { var perms = channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != userOrRoleId).FirstOrDefault(); await _api.DeleteChannelPermissions(channel.Id, userOrRoleId).ConfigureAwait(false); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } }
internal PermissionOverwrite(PermissionTarget targetType, string targetId, uint allow, uint deny) { TargetType = targetType; TargetId = targetId; Allow = new ChannelPermissions(allow); Allow.Lock(); Deny = new ChannelPermissions(deny); Deny.Lock(); }
public static string ToString(PermissionTarget value) { switch (value) { case PermissionTarget.User: return("member"); case PermissionTarget.Role: return("role"); default: throw new ArgumentException("Invalid permission target", nameof(value)); } }
private async Task RemovePermissionsRule(ulong userOrRoleId, PermissionTarget targetType) { try { var perms = PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != userOrRoleId).FirstOrDefault(); await Client.ClientAPI.Send(new RemoveChannelPermissionsRequest(Id, userOrRoleId)).ConfigureAwait(false); } catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { } }
private Task AddPermissionsRule(ulong targetId, PermissionTarget targetType, uint allow, uint deny) { var request = new AddChannelPermissionsRequest(Id) { TargetId = targetId, TargetType = targetType.Value, Allow = allow, Deny = deny }; return(Client.ClientAPI.Send(request)); }
private Task AddPermissionsRule(ulong targetId, PermissionTarget targetType, ChannelPermissions allow = null, ChannelPermissions deny = null) { var request = new AddChannelPermissionsRequest(Id) { TargetId = targetId, TargetType = targetType.Value, Allow = allow?.RawValue ?? 0, Deny = deny?.RawValue ?? 0 }; return(Client.ClientAPI.Send(request)); }
private Task AddOrUpdateOverwrite(ulong id, PermissionTarget type, ChannelTriStatePermissions permissions) { var request = new AddOrUpdateChannelPermissionsRequest(id) { TargetId = id, TargetType = EnumConverters.ToString(type), Allow = permissions.AllowValue, Deny = permissions.DenyValue }; return(_channel.Client.ClientAPI.Send(request)); }
internal void Update(ChannelInfo model) { Update(model as ChannelReference); if (model.Position != null) { Position = model.Position.Value; } if (model.Topic != null) { Topic = model.Topic; } if (model.PermissionOverwrites != null) { _permissionOverwrites = model.PermissionOverwrites .Select(x => new PermissionOverwrite(PermissionTarget.FromString(x.Type), x.Id, x.Allow, x.Deny)) .ToArray(); InvalidatePermissionsCache(); } }
private async Task RemovePermissionsRule(ulong userOrRoleId, PermissionTarget targetType) { try { var perms = PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != userOrRoleId).FirstOrDefault(); await Client.ClientAPI.Send(new RemoveChannelPermissionsRequest(Id, userOrRoleId)).ConfigureAwait(false); } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { } }
private Task AddPermissionsRule(ulong targetId, PermissionTarget targetType, ChannelPermissions allow = null, ChannelPermissions deny = null) { var request = new AddChannelPermissionsRequest(Id) { TargetId = targetId, TargetType = targetType.Value, Allow = allow?.RawValue ?? 0, Deny = deny?.RawValue ?? 0 }; return Client.ClientAPI.Send(request); }
private Task SetChannelPermissions(Channel channel, string targetId, PermissionTarget targetType, ChannelPermissions allow = null, ChannelPermissions deny = null) => _api.SetChannelPermissions(channel.Id, targetId, targetType.Value, allow?.RawValue ?? 0, deny?.RawValue ?? 0);
private async Task RemoveChannelPermissions(Channel channel, string userOrRoleId, PermissionTarget targetType) { try { var perms = channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != userOrRoleId).FirstOrDefault(); await _api.DeleteChannelPermissions(channel.Id, userOrRoleId).ConfigureAwait(false); } catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { } }
private Task AddPermissionsRule(ulong targetId, PermissionTarget targetType, uint allow, uint deny) { var request = new AddChannelPermissionsRequest(Id) { TargetId = targetId, TargetType = targetType.Value, Allow = allow, Deny = deny }; return Client.ClientAPI.Send(request); }
internal PermissionRule(PermissionTarget targetType, ulong targetId, uint allow, uint deny) { TargetType = targetType; TargetId = targetId; Permissions = new ChannelTriStatePermissions(allow, deny); }
/// <summary> Creates a new Overwrite with provided target information and modified permissions. </summary> public Overwrite(ulong targetId, PermissionTarget targetType, OverwritePermissions permissions) { TargetId = targetId; TargetType = targetType; Permissions = permissions; }