public async Task <bool> AddSecurityPrinciple(SecurityPrinciple principle, string contextUserId, bool bypassIntegrityCheck = false) { if (!await IsPrincipleInRole(contextUserId, StandardRoles.Administrator.Id, contextUserId) && !bypassIntegrityCheck) { _log?.Warning($"User {contextUserId} attempted to use AddSecurityPrinciple [{principle?.Id}] without being in required role."); return(false); } var principles = await GetSecurityPrinciples(); principles.Add(principle); await _store.Save <List <SecurityPrinciple> >("principles", principles); _log?.Information($"User {contextUserId} added security principle [{principle.Id}] {principle.Username}"); return(true); }
public async Task <bool> UpdateSecurityPrinciple(SecurityPrinciple principle, string contextUserId) { if (!await IsPrincipleInRole(contextUserId, StandardRoles.Administrator.Id, contextUserId)) { _log?.Warning($"User {contextUserId} attempted to use UpdateSecurityPrinciple [{principle?.Id}] without being in required role."); return(false); } var principles = await GetSecurityPrinciples(); var existing = principles.Find(p => p.Id == principle.Id); if (existing != null) { principles.Remove(existing); } principles.Add(principle); await _store.Save <List <SecurityPrinciple> >("principles", principles); _log?.Information($"User {contextUserId} updated security principle [{principle.Id}] {principle.Username}"); return(true); }