public async Task <IActionResult> DoSystemGuildPatch(string systemRef, ulong guild_id, [FromBody] JObject data) { var system = await ResolveSystem(systemRef); if (ContextFor(system) != LookupContext.ByOwner) { throw Errors.GenericMissingPermissions; } var settings = await _repo.GetSystemGuild(guild_id, system.Id, false); if (settings == null) { throw Errors.SystemGuildNotFound; } var patch = SystemGuildPatch.FromJson(data); patch.AssertIsValid(); if (patch.Errors.Count > 0) { throw new ModelParseError(patch.Errors); } var newSettings = await _repo.UpdateSystemGuild(system.Id, guild_id, patch); return(Ok(newSettings.ToJson())); }
private Task UpdateAutoproxy(Context ctx, AutoproxyMode autoproxyMode, MemberId?autoproxyMember) { var patch = new SystemGuildPatch { AutoproxyMode = autoproxyMode, AutoproxyMember = autoproxyMember }; return(_db.Execute(conn => _repo.UpsertSystemGuild(conn, ctx.System.Id, ctx.Guild.Id, patch))); }
private async Task UpdateAutoproxy(Context ctx, AutoproxyMode autoproxyMode, MemberId?autoproxyMember) { await ctx.Repository.GetSystemGuild(ctx.Guild.Id, ctx.System.Id); var patch = new SystemGuildPatch { AutoproxyMode = autoproxyMode, AutoproxyMember = autoproxyMember }; await ctx.Repository.UpdateSystemGuild(ctx.System.Id, ctx.Guild.Id, patch); }
public async Task <SystemGuildSettings> UpdateSystemGuild(SystemId system, ulong guild, SystemGuildPatch patch) { _logger.Information("Updated {SystemId} in guild {GuildId}: {@SystemGuildPatch}", system, guild, patch); var query = patch.Apply(new Query("system_guild").Where("system", system).Where("guild", guild)); var settings = await _db.QueryFirst <SystemGuildSettings>(query, "returning *"); _ = _dispatch.Dispatch(system, guild, patch); return(settings); }
public async Task <IActionResult> DoSystemGuildPatch(string systemRef, ulong guild_id, [FromBody] JObject data) { var system = await ResolveSystem(systemRef); if (ContextFor(system) != LookupContext.ByOwner) { throw Errors.GenericMissingPermissions; } var settings = await _repo.GetSystemGuild(guild_id, system.Id, false); if (settings == null) { throw Errors.SystemGuildNotFound; } MemberId?memberId = null; if (data.ContainsKey("autoproxy_member")) { if (data["autoproxy_member"].Type != JTokenType.Null) { var member = await ResolveMember(data.Value <string>("autoproxy_member")); if (member == null) { throw Errors.MemberNotFound; } memberId = member.Id; } } else { memberId = settings.AutoproxyMember; } var patch = SystemGuildPatch.FromJson(data, memberId); patch.AssertIsValid(); if (patch.Errors.Count > 0) { throw new ModelParseError(patch.Errors); } // this is less than great, but at least it's legible if (patch.AutoproxyMember.Value == null) { if (patch.AutoproxyMode.IsPresent) { if (patch.AutoproxyMode.Value == AutoproxyMode.Member) { throw Errors.MissingAutoproxyMember; } } else if (settings.AutoproxyMode == AutoproxyMode.Member) { throw Errors.MissingAutoproxyMember; } } else { if (patch.AutoproxyMode.IsPresent) { if (patch.AutoproxyMode.Value == AutoproxyMode.Latch) { throw Errors.PatchLatchMemberError; } } else if (settings.AutoproxyMode == AutoproxyMode.Latch) { throw Errors.PatchLatchMemberError; } } var newSettings = await _repo.UpdateSystemGuild(system.Id, guild_id, patch); PKMember?newMember = null; if (newSettings.AutoproxyMember != null) { newMember = await _repo.GetMember(newSettings.AutoproxyMember.Value); } return(Ok(newSettings.ToJson(newMember?.Hid))); }