Raids and RaidTemplates are now only editable by their owner or moderators
reworked user rights
This commit is contained in:
parent
cb683723b7
commit
2bf630f3a1
25 changed files with 258 additions and 270 deletions
|
@ -2,28 +2,28 @@
|
|||
{
|
||||
public static class Constants
|
||||
{
|
||||
|
||||
|
||||
public const string ClaimType = "Role";
|
||||
public static readonly int RaidEditPowerLevel = Roles.Moderator.PowerLevel;
|
||||
|
||||
public static class Roles
|
||||
{
|
||||
public const string User = "User";
|
||||
public const string RaidLead = "RaidLead";
|
||||
public const string GuildLead = "GuildLead";
|
||||
public const string Admin = "Admin";
|
||||
public static readonly RoleConstant User = new RoleConstant("user", 20);
|
||||
public static readonly RoleConstant RaidLead = new RoleConstant("RaidLead", 40);
|
||||
public static readonly RoleConstant Moderator = new RoleConstant("Moderator", 70);
|
||||
public static readonly RoleConstant Admin = new RoleConstant("Admin", 100);
|
||||
}
|
||||
|
||||
public static List<string> GetAllRoles()
|
||||
public class RoleConstant
|
||||
{
|
||||
return typeof(Roles).GetFields().Select(f => f.GetValue(f)).Cast<string>().ToList();
|
||||
public readonly string Name;
|
||||
public readonly int PowerLevel;
|
||||
|
||||
public RoleConstant(string name, int powerLevel)
|
||||
{
|
||||
Name = name;
|
||||
PowerLevel = powerLevel;
|
||||
}
|
||||
}
|
||||
|
||||
public static class RoleLevels
|
||||
{
|
||||
public const int UserLevel = 20;
|
||||
public const int RaidLeadLevel = 55;
|
||||
public const int GuildLeadLevel = 65;
|
||||
public const int AdminLevel = 80;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,21 +10,21 @@ namespace Lieb.Data
|
|||
public static void Initialize(LiebContext context)
|
||||
{
|
||||
//add special Roles
|
||||
if (context.LiebRoles.FirstOrDefault(r => r.RoleName == Constants.Roles.Admin) == null)
|
||||
if (context.LiebRoles.FirstOrDefault(r => r.RoleName == Constants.Roles.Admin.Name) == null)
|
||||
{
|
||||
context.LiebRoles.Add(new LiebRole() { RoleName = Constants.Roles.Admin, IsSystemRole = true, Level = Constants.RoleLevels.AdminLevel, LevelToAssign = Constants.RoleLevels.AdminLevel });
|
||||
context.LiebRoles.Add(new LiebRole() { RoleName = Constants.Roles.Admin.Name, Type = RoleType.SystemRole, Level = Constants.Roles.Admin.PowerLevel, LevelToAssign = Constants.Roles.Admin.PowerLevel });
|
||||
}
|
||||
if (context.LiebRoles.FirstOrDefault(r => r.RoleName == Constants.Roles.GuildLead) == null)
|
||||
if (context.LiebRoles.FirstOrDefault(r => r.RoleName == Constants.Roles.Moderator.Name) == null)
|
||||
{
|
||||
context.LiebRoles.Add(new LiebRole() { RoleName = Constants.Roles.GuildLead, IsSystemRole = true, Level = Constants.RoleLevels.GuildLeadLevel, LevelToAssign = Constants.RoleLevels.AdminLevel });
|
||||
context.LiebRoles.Add(new LiebRole() { RoleName = Constants.Roles.Moderator.Name, Type = RoleType.SystemRole, Level = Constants.Roles.Moderator.PowerLevel, LevelToAssign = Constants.Roles.Admin.PowerLevel });
|
||||
}
|
||||
if (context.LiebRoles.FirstOrDefault(r => r.RoleName == Constants.Roles.RaidLead) == null)
|
||||
if (context.LiebRoles.FirstOrDefault(r => r.RoleName == Constants.Roles.RaidLead.Name) == null)
|
||||
{
|
||||
context.LiebRoles.Add(new LiebRole() { RoleName = Constants.Roles.RaidLead, IsSystemRole = true, Level = Constants.RoleLevels.RaidLeadLevel, LevelToAssign = Constants.RoleLevels.GuildLeadLevel });
|
||||
context.LiebRoles.Add(new LiebRole() { RoleName = Constants.Roles.RaidLead.Name, Type = RoleType.SystemRole, Level = Constants.Roles.RaidLead.PowerLevel, LevelToAssign = Constants.Roles.Moderator.PowerLevel });
|
||||
}
|
||||
if (context.LiebRoles.FirstOrDefault(r => r.RoleName == Constants.Roles.User) == null)
|
||||
if (context.LiebRoles.FirstOrDefault(r => r.RoleName == Constants.Roles.User.Name) == null)
|
||||
{
|
||||
context.LiebRoles.Add(new LiebRole() { RoleName = Constants.Roles.User, IsSystemRole = true, Level = Constants.RoleLevels.UserLevel, LevelToAssign = Constants.RoleLevels.AdminLevel + 1 });
|
||||
context.LiebRoles.Add(new LiebRole() { RoleName = Constants.Roles.User.Name, Type = RoleType.SystemRole, Level = Constants.Roles.User.PowerLevel, LevelToAssign = Constants.Roles.Admin.PowerLevel + 1 });
|
||||
}
|
||||
context.SaveChanges();
|
||||
|
||||
|
@ -52,10 +52,10 @@ namespace Lieb.Data
|
|||
context.SaveChanges();
|
||||
|
||||
|
||||
int AdminRoleId = context.LiebRoles.FirstOrDefault(x => x.RoleName == Constants.Roles.Admin).LiebRoleId;
|
||||
int GuildLeadRoleId = context.LiebRoles.FirstOrDefault(x => x.RoleName == Constants.Roles.GuildLead).LiebRoleId;
|
||||
int RaidLeadRoleId = context.LiebRoles.FirstOrDefault(x => x.RoleName == Constants.Roles.RaidLead).LiebRoleId;
|
||||
int UserRoleId = context.LiebRoles.FirstOrDefault(x => x.RoleName == Constants.Roles.User).LiebRoleId;
|
||||
int AdminRoleId = context.LiebRoles.FirstOrDefault(x => x.RoleName == Constants.Roles.Admin.Name).LiebRoleId;
|
||||
int GuildLeadRoleId = context.LiebRoles.FirstOrDefault(x => x.RoleName == Constants.Roles.Moderator.Name).LiebRoleId;
|
||||
int RaidLeadRoleId = context.LiebRoles.FirstOrDefault(x => x.RoleName == Constants.Roles.RaidLead.Name).LiebRoleId;
|
||||
int UserRoleId = context.LiebRoles.FirstOrDefault(x => x.RoleName == Constants.Roles.User.Name).LiebRoleId;
|
||||
|
||||
var assignments = new RoleAssignment[]
|
||||
{
|
||||
|
|
|
@ -34,24 +34,14 @@ namespace Lieb.Data
|
|||
{
|
||||
user.GuildWars2Accounts.Add(account);
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
GuildWars2Account? accountToChange = context.GuildWars2Accounts
|
||||
.Include(a => a.EquippedBuilds)
|
||||
.FirstOrDefault(a => a.GuildWars2AccountId == account.GuildWars2AccountId);
|
||||
|
||||
if (accountToChange != null)
|
||||
{
|
||||
accountToChange.AccountName = account.AccountName;
|
||||
accountToChange.ApiKey = account.ApiKey;
|
||||
|
||||
context.Update(account);
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAccount(int accountId)
|
||||
{
|
||||
|
|
|
@ -20,28 +20,14 @@ namespace Lieb.Data
|
|||
if (build.GuildWars2BuildId == 0)
|
||||
{
|
||||
context.GuildWars2Builds.Add(build);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
GuildWars2Build? buildToChange = await context.GuildWars2Builds
|
||||
.FirstOrDefaultAsync(r => r.GuildWars2BuildId == build.GuildWars2BuildId);
|
||||
|
||||
if (buildToChange != null)
|
||||
{
|
||||
buildToChange.BuildName = build.BuildName;
|
||||
buildToChange.Might = build.Might;
|
||||
buildToChange.Quickness = build.Quickness;
|
||||
buildToChange.Alacrity = build.Alacrity;
|
||||
buildToChange.Heal = build.Heal;
|
||||
buildToChange.Class = build.Class;
|
||||
buildToChange.EliteSpecialization = build.EliteSpecialization;
|
||||
|
||||
context.Update(build);
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteBuild(int buildId)
|
||||
{
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace Lieb.Data
|
|||
.FirstOrDefault(r => r.RaidId == raidId);
|
||||
}
|
||||
|
||||
public async Task AddOrEditRaid(Raid raid)
|
||||
public async Task AddOrEditRaid(Raid raid, List<PlannedRaidRole> rolesToDelete, List<RaidReminder> remindersToDelete)
|
||||
{
|
||||
if (raid != null)
|
||||
{
|
||||
|
@ -57,54 +57,26 @@ namespace Lieb.Data
|
|||
}
|
||||
else
|
||||
{
|
||||
Raid? raidToChange = await context.Raids
|
||||
.Include(r => r.Roles)
|
||||
.Include(r => r.SignUpHistory)
|
||||
.Include(r => r.Reminders)
|
||||
.Include(r => r.SignUps)
|
||||
.FirstOrDefaultAsync(r => r.RaidId == raid.RaidId);
|
||||
if (raidToChange != null)
|
||||
{
|
||||
raidToChange.Title = raid.Title;
|
||||
raidToChange.Description = raid.Description;
|
||||
raidToChange.StartTimeUTC = raid.StartTimeUTC;
|
||||
raidToChange.EndTimeUTC = raid.EndTimeUTC;
|
||||
raidToChange.Organizer = raid.Organizer;
|
||||
raidToChange.Guild = raid.Guild;
|
||||
raidToChange.VoiceChat = raid.VoiceChat;
|
||||
raidToChange.RaidType = raid.RaidType;
|
||||
raidToChange.RequiredRole = raid.RequiredRole;
|
||||
raidToChange.FreeForAllTimeUTC = raid.FreeForAllTimeUTC;
|
||||
raidToChange.DiscordMessageId = raid.DiscordMessageId;
|
||||
raidToChange.DiscordChannelId = raid.DiscordChannelId;
|
||||
raidToChange.DiscordGuildId = raid.DiscordGuildId;
|
||||
context.Update(raid);
|
||||
context.PlannedRaidRoles.RemoveRange(rolesToDelete);
|
||||
context.RaidReminders.RemoveRange(remindersToDelete);
|
||||
|
||||
if (raidToChange.RaidType == RaidType.Planned)
|
||||
//move users back to "Random" role
|
||||
if (raid.RaidType != RaidType.Planned)
|
||||
{
|
||||
EditRoles(raidToChange, raid, context);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!raidToChange.Roles.Where(r => r.IsRandomSignUpRole).Any())
|
||||
{
|
||||
raidToChange.Roles.Add(raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole));
|
||||
}
|
||||
int randomRoleId = raidToChange.Roles.FirstOrDefault(r => r.IsRandomSignUpRole).PlannedRaidRoleId;
|
||||
foreach (RaidSignUp signUp in raidToChange.SignUps)
|
||||
int randomRoleId = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole).PlannedRaidRoleId;
|
||||
foreach (RaidSignUp signUp in raid.SignUps)
|
||||
{
|
||||
if (randomRoleId == 0)
|
||||
{
|
||||
signUp.PlannedRaidRole = raidToChange.Roles.FirstOrDefault(r => r.IsRandomSignUpRole);
|
||||
signUp.PlannedRaidRole = raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole);
|
||||
}
|
||||
else
|
||||
{
|
||||
signUp.PlannedRaidRoleId = randomRoleId;
|
||||
}
|
||||
}
|
||||
context.PlannedRaidRoles.RemoveRange(raidToChange.Roles.Where(r => !r.IsRandomSignUpRole));
|
||||
}
|
||||
|
||||
EditReminders(raidToChange, raid, context);
|
||||
context.PlannedRaidRoles.RemoveRange(raid.Roles.Where(r => !r.IsRandomSignUpRole));
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
|
@ -112,64 +84,6 @@ namespace Lieb.Data
|
|||
}
|
||||
}
|
||||
|
||||
private void EditRoles(Raid raidToEdit, Raid raid, LiebContext context)
|
||||
{
|
||||
List<PlannedRaidRole> rolesToRemove = new List<PlannedRaidRole>();
|
||||
foreach (PlannedRaidRole role in raidToEdit.Roles)
|
||||
{
|
||||
PlannedRaidRole? newRole = raid.Roles.FirstOrDefault(r => r.PlannedRaidRoleId == role.PlannedRaidRoleId);
|
||||
if (newRole != null)
|
||||
{
|
||||
role.Spots = newRole.Spots;
|
||||
role.Name = newRole.Name;
|
||||
role.Description = newRole.Description;
|
||||
}
|
||||
else
|
||||
{
|
||||
rolesToRemove.Add(role);
|
||||
}
|
||||
}
|
||||
foreach (PlannedRaidRole role in rolesToRemove)
|
||||
{
|
||||
raidToEdit.Roles.Remove(role);
|
||||
context.PlannedRaidRoles.Remove(role);
|
||||
}
|
||||
foreach (PlannedRaidRole role in raid.Roles.Where(r => r.PlannedRaidRoleId == 0))
|
||||
{
|
||||
raidToEdit.Roles.Add(role);
|
||||
}
|
||||
}
|
||||
|
||||
private void EditReminders(Raid raidToEdit, Raid raid, LiebContext context)
|
||||
{
|
||||
List<RaidReminder> reminderToRemove = new List<RaidReminder>();
|
||||
foreach (RaidReminder reminder in raidToEdit.Reminders)
|
||||
{
|
||||
RaidReminder? newReminder = raid.Reminders.FirstOrDefault(r => r.RaidReminderId == reminder.RaidReminderId);
|
||||
if (newReminder != null)
|
||||
{
|
||||
reminder.Type = newReminder.Type;
|
||||
reminder.Message = newReminder.Message;
|
||||
reminder.HoursBeforeRaid = newReminder.HoursBeforeRaid;
|
||||
reminder.ChannelId = newReminder.ChannelId;
|
||||
reminder.Sent = newReminder.Sent;
|
||||
}
|
||||
else
|
||||
{
|
||||
reminderToRemove.Add(reminder);
|
||||
}
|
||||
}
|
||||
foreach (RaidReminder reminder in reminderToRemove)
|
||||
{
|
||||
raidToEdit.Reminders.Remove(reminder);
|
||||
context.RaidReminders.Remove(reminder);
|
||||
}
|
||||
foreach (PlannedRaidRole role in raid.Roles.Where(r => r.PlannedRaidRoleId == 0))
|
||||
{
|
||||
raidToEdit.Roles.Add(role);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteRaid(int raidId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
|
@ -310,14 +224,14 @@ namespace Lieb.Data
|
|||
|
||||
if (raid.RaidType == RaidType.Planned)
|
||||
{
|
||||
//if (raid.MoveFlexAllowed)
|
||||
if (raid.MoveFlexUsers)
|
||||
{
|
||||
return IsRoleSignUpAllowed(raid, liebUserId, plannedRoleId, signUpType, moveFlexUser, new List<int>()).Result;
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// return IsRoleSignUpAllowed(liebUserId, plannedRoleId, signUpType);
|
||||
//}
|
||||
else
|
||||
{
|
||||
return IsRoleSignUpAllowed(liebUserId, plannedRoleId, signUpType);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -31,7 +31,7 @@ namespace Lieb.Data
|
|||
.FirstOrDefault(t => t.RaidTemplateId == raidTemplateId);
|
||||
}
|
||||
|
||||
public async Task AddOrEditTemplate(RaidTemplate template)
|
||||
public async Task AddOrEditTemplate(RaidTemplate template, List<PlannedRaidRole> rolesToDelete, List<RaidReminder> remindersToDelete)
|
||||
{
|
||||
if (template != null)
|
||||
{
|
||||
|
@ -39,39 +39,14 @@ namespace Lieb.Data
|
|||
if (template.RaidTemplateId == 0)
|
||||
{
|
||||
context.RaidTemplates.Add(template);
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
RaidTemplate raidToChange = await context.RaidTemplates
|
||||
.Include(r => r.Roles)
|
||||
.Include(r => r.Reminders)
|
||||
.FirstOrDefaultAsync(r => r.RaidTemplateId == template.RaidTemplateId);
|
||||
raidToChange.Title = template.Title;
|
||||
raidToChange.Description = template.Description;
|
||||
raidToChange.Organizer = template.Organizer;
|
||||
raidToChange.Guild = template.Guild;
|
||||
raidToChange.VoiceChat = template.VoiceChat;
|
||||
raidToChange.RaidType = template.RaidType;
|
||||
raidToChange.RequiredRole = template.RequiredRole;
|
||||
raidToChange.DiscordChannelId = template.DiscordChannelId;
|
||||
raidToChange.DiscordGuildId = template.DiscordGuildId;
|
||||
raidToChange.StartTime = template.StartTime;
|
||||
raidToChange.EndTime = template.EndTime;
|
||||
raidToChange.FreeForAllTime = template.FreeForAllTime;
|
||||
raidToChange.TimeZone = template.TimeZone;
|
||||
raidToChange.Interval = template.Interval;
|
||||
raidToChange.CreateDaysBefore = template.CreateDaysBefore;
|
||||
|
||||
context.PlannedRaidRoles.RemoveRange(raidToChange.Roles);
|
||||
context.RaidReminders.RemoveRange(raidToChange.Reminders);
|
||||
raidToChange.Roles.Clear();
|
||||
raidToChange.Reminders.Clear();
|
||||
raidToChange.Roles = template.Roles;
|
||||
raidToChange.Reminders = template.Reminders;
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
context.Update(template);
|
||||
context.PlannedRaidRoles.RemoveRange(rolesToDelete);
|
||||
context.RaidReminders.RemoveRange(remindersToDelete);
|
||||
}
|
||||
await context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace Lieb.Data
|
|||
.FirstOrDefault(u => u.LiebUserId == userId);
|
||||
}
|
||||
|
||||
public LiebUser GetLiebUserSmall(ulong discordId)
|
||||
public LiebUser GetLiebUserGW2AccountOnly(ulong discordId)
|
||||
{
|
||||
if (discordId > 0)
|
||||
{
|
||||
|
@ -69,7 +69,7 @@ namespace Lieb.Data
|
|||
return new LiebUser();
|
||||
}
|
||||
|
||||
public LiebUser GetLiebUserSmall(int userId)
|
||||
public LiebUser GetLiebGW2AccountOnly(int userId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
return context.LiebUsers
|
||||
|
@ -145,6 +145,36 @@ namespace Lieb.Data
|
|||
await context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public int GetPowerLevel(int userId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
LiebUser? user = context.LiebUsers
|
||||
.Include(u => u.RoleAssignments)
|
||||
.ThenInclude(r => r.LiebRole)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(u => u.LiebUserId == userId);
|
||||
if (user != null)
|
||||
{
|
||||
return user.RoleAssignments.Max(a => a.LiebRole.Level);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int GetPowerLevel(ulong discordId)
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
LiebUser? user = context.LiebUsers
|
||||
.Include(u => u.RoleAssignments)
|
||||
.ThenInclude(r => r.LiebRole)
|
||||
.AsNoTracking()
|
||||
.FirstOrDefault(u => u.DiscordUserId == discordId);
|
||||
if (user != null)
|
||||
{
|
||||
return user.RoleAssignments.Max(a => a.LiebRole.Level);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public List<LiebRole> GetLiebRoles()
|
||||
{
|
||||
using var context = _contextFactory.CreateDbContext();
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace Discord.OAuth2
|
|||
}
|
||||
else
|
||||
{
|
||||
LiebRole standardRole = await _LiebDbcontext.LiebRoles.FirstOrDefaultAsync(m => m.RoleName == Constants.Roles.User);
|
||||
LiebRole standardRole = await _LiebDbcontext.LiebRoles.FirstOrDefaultAsync(m => m.RoleName == Constants.Roles.User.Name);
|
||||
string userName = context.Identity.Claims.FirstOrDefault(x => x.Type == ClaimTypes.Name).Value;
|
||||
LiebUser newUser = new LiebUser()
|
||||
{
|
||||
|
@ -78,7 +78,7 @@ namespace Discord.OAuth2
|
|||
_LiebDbcontext.RoleAssignments.Add(roleAssignment);
|
||||
await _LiebDbcontext.SaveChangesAsync();
|
||||
|
||||
context.Identity.AddClaim(new Claim(Constants.ClaimType, Constants.Roles.User));
|
||||
context.Identity.AddClaim(new Claim(Constants.ClaimType, Constants.Roles.User.Name));
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@ namespace Lieb.Models.GuildWars2.Raid
|
|||
|
||||
public string RequiredRole { get; set; } = String.Empty;
|
||||
|
||||
public bool MoveFlexUsers { get; set; } = true;
|
||||
|
||||
public int RaidOwnerId { get; set; }
|
||||
|
||||
//role name, number of spots
|
||||
public ICollection<PlannedRaidRole> Roles { get; set; } = new HashSet<PlannedRaidRole>();
|
||||
|
||||
|
|
|
@ -2,6 +2,13 @@
|
|||
|
||||
namespace Lieb.Models
|
||||
{
|
||||
public enum RoleType
|
||||
{
|
||||
GuildRole = 1,
|
||||
SystemRole = 2,
|
||||
UserDefinedRole = 3
|
||||
}
|
||||
|
||||
public class LiebRole
|
||||
{
|
||||
public int LiebRoleId { get; set; }
|
||||
|
@ -10,7 +17,7 @@ namespace Lieb.Models
|
|||
[StringLength(40, ErrorMessage = "RoleName too long (40 character limit).")]
|
||||
public string RoleName { get; set; } = string.Empty;
|
||||
|
||||
public bool IsSystemRole { get; set; } = false;
|
||||
public RoleType Type { get; set; }
|
||||
|
||||
public int Level { get; set; } = 20;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<h3>BuildEdit</h3>
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin" Context="authorizationContext">
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin.Name" Context="authorizationContext">
|
||||
<EditForm Model="@_build" OnValidSubmit="@HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
<h3>BuildOverview</h3>
|
||||
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin">
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin.Name">
|
||||
<Authorized>
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="buildedit">
|
||||
|
|
|
@ -75,13 +75,15 @@
|
|||
<div>
|
||||
<AuthorizeView>
|
||||
<button class="controlButton raidButton" @onclick="() => SignOffClicked()">Sign Off</button>
|
||||
</AuthorizeView>
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead">
|
||||
|
||||
@if (_raid.RaidOwnerId == _user.LiebUserId || _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel)
|
||||
{
|
||||
<button class="controlButton raidButton" @onclick="() => EditClicked()">Edit</button>
|
||||
@if (_raid.RaidType != RaidType.Planned)
|
||||
{
|
||||
<button class="controlButton raidButton" type=button @onclick="() => RandomizeClicked()">Randomize</button>
|
||||
}
|
||||
}
|
||||
</AuthorizeView>
|
||||
</div>
|
||||
}
|
||||
|
|
|
@ -4,16 +4,18 @@
|
|||
@using Lieb.Models
|
||||
@using Lieb.Models.GuildWars2.Raid
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Security.Claims
|
||||
@inject RaidService RaidService
|
||||
@inject UserService UserService
|
||||
@inject TimeZoneService TimeZoneService
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||
@inject IJSRuntime JsRuntime
|
||||
|
||||
|
||||
<h3>CreateRaid</h3>
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead" Context="authorizationContext">
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead.Name" Context="authorizationContext">
|
||||
<EditForm Model="@_raid" OnValidSubmit="@HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
@{
|
||||
|
@ -70,7 +72,7 @@
|
|||
<option value="">Not Locked</option>
|
||||
@foreach(LiebRole role in UserService.GetLiebRoles())
|
||||
{
|
||||
if (!role.IsSystemRole)
|
||||
if (role.Type != RoleType.SystemRole)
|
||||
{
|
||||
<option value="@role.RoleName">@role.RoleName</option>
|
||||
}
|
||||
|
@ -151,11 +153,11 @@
|
|||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
|
||||
[Parameter]
|
||||
public string raidId { get; set; }
|
||||
|
||||
public Raid _raid;
|
||||
private LiebUser _user;
|
||||
|
||||
private string _errorMessage = string.Empty;
|
||||
|
||||
|
@ -165,13 +167,30 @@
|
|||
private DateTimeOffset _freeForAllDate = DateTime.Now.Date;
|
||||
private DateTimeOffset _freeForAllTime;
|
||||
|
||||
private List<PlannedRaidRole> _rolesToDelete = new List<PlannedRaidRole>();
|
||||
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
if (authState != null)
|
||||
{
|
||||
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
||||
_user = UserService.GetLiebUser(discordId);
|
||||
}
|
||||
if(_user == null)
|
||||
{
|
||||
NavigationManager.NavigateTo("");
|
||||
}
|
||||
|
||||
if(!string.IsNullOrEmpty(raidId) && int.TryParse(raidId, out int parsedId))
|
||||
{
|
||||
_raid = RaidService.GetRaid(parsedId);
|
||||
|
||||
if (_raid != null && (_raid.RaidOwnerId == _user.LiebUserId
|
||||
|| _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel))
|
||||
{
|
||||
_startTime = await TimeZoneService.GetLocalDateTime(_raid.StartTimeUTC);
|
||||
_endTime = await TimeZoneService.GetLocalDateTime(_raid.EndTimeUTC);
|
||||
_raidDate = _startTime.Date;
|
||||
|
@ -183,6 +202,11 @@
|
|||
_raid = new Raid();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_raid = new Raid();
|
||||
}
|
||||
}
|
||||
|
||||
async Task AddRoleClicked()
|
||||
{
|
||||
|
@ -192,6 +216,10 @@
|
|||
|
||||
async Task DeleteRoleClicked(PlannedRaidRole role)
|
||||
{
|
||||
if(role.PlannedRaidRoleId != 0)
|
||||
{
|
||||
_rolesToDelete.Add(role);
|
||||
}
|
||||
_raid.Roles.Remove(role);
|
||||
}
|
||||
|
||||
|
@ -209,7 +237,7 @@
|
|||
{
|
||||
if(_raid.RaidType != RaidType.Planned)
|
||||
{
|
||||
PlannedRaidRole role = _raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole);
|
||||
PlannedRaidRole? role = _raid.Roles.FirstOrDefault(r => r.IsRandomSignUpRole);
|
||||
int randomRoleId = role != null ? role.PlannedRaidRoleId : 0;
|
||||
_raid.Roles.Clear();
|
||||
_raid.Roles.Add(new PlannedRaidRole()
|
||||
|
@ -228,8 +256,6 @@
|
|||
return;
|
||||
}
|
||||
|
||||
//_raid.TimeZone = await TimeZoneService.GetUserTimeZone();
|
||||
|
||||
_raid.StartTimeUTC = await TimeZoneService.GetUTCDateTime(_raidDate.Date + _startTime.TimeOfDay);
|
||||
if(_startTime.TimeOfDay > _endTime.TimeOfDay)
|
||||
{
|
||||
|
@ -241,7 +267,12 @@
|
|||
}
|
||||
_raid.FreeForAllTimeUTC = await TimeZoneService.GetUTCDateTime(_freeForAllDate.Date + _freeForAllTime.TimeOfDay);
|
||||
|
||||
await RaidService.AddOrEditRaid(_raid);
|
||||
if (_raid.RaidOwnerId == 0)
|
||||
{
|
||||
_raid.RaidOwnerId = _user.LiebUserId;
|
||||
}
|
||||
|
||||
await RaidService.AddOrEditRaid(_raid, _rolesToDelete, new List<RaidReminder>());
|
||||
NavigationManager.NavigateTo("raidoverview");
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
<h3>RaidOverview</h3>
|
||||
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead">
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead.Name">
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="raidedit">
|
||||
<span class="oi oi-plus" aria-hidden="true"></span> Add Raid
|
||||
|
@ -31,7 +31,7 @@
|
|||
<option value="No Group">No Group</option>
|
||||
@foreach(LiebRole role in UserService.GetLiebRoles())
|
||||
{
|
||||
if (!role.IsSystemRole)
|
||||
if (role.Type != RoleType.SystemRole)
|
||||
{
|
||||
<option value="@role.RoleName">@role.RoleName</option>
|
||||
}
|
||||
|
@ -64,7 +64,7 @@
|
|||
if (authState.User.Identity.IsAuthenticated)
|
||||
{
|
||||
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
||||
_user = UserService.GetLiebUserSmall(discordId);
|
||||
_user = UserService.GetLiebUser(discordId);
|
||||
}
|
||||
|
||||
_raids = RaidService.GetRaids();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
@inject UserService UserService
|
||||
@inject RaidService RaidService
|
||||
@inject TimeZoneService TimeZoneService
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject RaidRandomizerService RaidRandomizerService
|
||||
|
||||
<body>
|
||||
|
@ -58,13 +59,11 @@
|
|||
</div>
|
||||
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead">
|
||||
<div class="nav-item px-3">
|
||||
@{string navLink = $"raidtemplateedit/{_template.RaidTemplateId}";}
|
||||
<NavLink class="nav-link" href="@navLink">
|
||||
<span class="oi oi-plus" aria-hidden="true"></span> Edit
|
||||
</NavLink>
|
||||
</div>
|
||||
<AuthorizeView>
|
||||
@if (_template.RaidOwnerId == _user.LiebUserId || _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel)
|
||||
{
|
||||
<button class="controlButton raidButton" @onclick="() => EditClicked()">Edit</button>
|
||||
}
|
||||
</AuthorizeView>
|
||||
</body>
|
||||
|
||||
|
@ -72,7 +71,15 @@
|
|||
[Parameter]
|
||||
public RaidTemplate _template { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public LiebUser? _user { get; set; }
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
}
|
||||
|
||||
async Task EditClicked()
|
||||
{
|
||||
NavigationManager.NavigateTo($"raidtemplateedit/{_template.RaidTemplateId}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,16 +4,18 @@
|
|||
@using Lieb.Models
|
||||
@using Lieb.Models.GuildWars2.Raid
|
||||
@using System.ComponentModel.DataAnnotations
|
||||
@using System.Security.Claims
|
||||
@inject RaidTemplateService RaidTemplateService
|
||||
@inject UserService UserService
|
||||
@inject TimeZoneService TimeZoneService
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||
@inject IJSRuntime JsRuntime
|
||||
|
||||
|
||||
<h3>CreateRaid</h3>
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead" Context="authorizationContext">
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead.Name" Context="authorizationContext">
|
||||
<EditForm Model="@_template" OnValidSubmit="@HandleValidSubmit">
|
||||
<DataAnnotationsValidator />
|
||||
@{
|
||||
|
@ -83,7 +85,7 @@
|
|||
<option value="">Not Locked</option>
|
||||
@foreach(LiebRole role in UserService.GetLiebRoles())
|
||||
{
|
||||
if (!role.IsSystemRole)
|
||||
if (role.Type != RoleType.SystemRole)
|
||||
{
|
||||
<option value="@role.RoleName">@role.RoleName</option>
|
||||
}
|
||||
|
@ -177,6 +179,7 @@
|
|||
public string raidId { get; set; }
|
||||
|
||||
public RaidTemplate _template;
|
||||
private LiebUser _user;
|
||||
|
||||
private string _errorMessage = string.Empty;
|
||||
|
||||
|
@ -187,13 +190,29 @@
|
|||
private DateTimeOffset _freeForAllTime;
|
||||
private string _userTimeZone = string.Empty;
|
||||
|
||||
private List<PlannedRaidRole> _rolesToDelete = new List<PlannedRaidRole>();
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
if (authState != null)
|
||||
{
|
||||
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
||||
_user = UserService.GetLiebUser(discordId);
|
||||
}
|
||||
if(_user == null)
|
||||
{
|
||||
NavigationManager.NavigateTo("");
|
||||
}
|
||||
|
||||
if(!string.IsNullOrEmpty(raidId) && int.TryParse(raidId, out int parsedId))
|
||||
{
|
||||
_template = RaidTemplateService.GetTemplate(parsedId);
|
||||
|
||||
if (_template != null && (_template.RaidOwnerId == _user.LiebUserId
|
||||
|| _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel))
|
||||
{
|
||||
_startTime = _template.StartTime;
|
||||
_endTime = _template.EndTime;
|
||||
_raidDate = _startTime.Date;
|
||||
|
@ -204,6 +223,11 @@
|
|||
{
|
||||
_template = new RaidTemplate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_template = new RaidTemplate();
|
||||
}
|
||||
_userTimeZone = await TimeZoneService.GetUserTimeZone();
|
||||
}
|
||||
|
||||
|
@ -215,6 +239,10 @@
|
|||
|
||||
async Task DeleteRoleClicked(PlannedRaidRole role)
|
||||
{
|
||||
if(role.PlannedRaidRoleId != 0)
|
||||
{
|
||||
_rolesToDelete.Add(role);
|
||||
}
|
||||
_template.Roles.Remove(role);
|
||||
}
|
||||
|
||||
|
@ -260,7 +288,12 @@
|
|||
}
|
||||
_template.FreeForAllTime = _freeForAllDate.Date + _freeForAllTime.TimeOfDay;
|
||||
|
||||
await RaidTemplateService.AddOrEditTemplate(_template);
|
||||
if (_template.RaidOwnerId == 0)
|
||||
{
|
||||
_template.RaidOwnerId = _user.LiebUserId;
|
||||
}
|
||||
|
||||
await RaidTemplateService.AddOrEditTemplate(_template, _rolesToDelete, new List<RaidReminder>());
|
||||
NavigationManager.NavigateTo("raidtemplateoverview");
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
<h3>RaidTemplateOverview</h3>
|
||||
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead">
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead.Name">
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="raidtemplateedit">
|
||||
<span class="oi oi-plus" aria-hidden="true"></span> Add Raid
|
||||
|
@ -22,17 +22,23 @@
|
|||
@foreach (var raid in _templates.OrderBy(r => r.StartTime))
|
||||
{
|
||||
<br />
|
||||
<RaidTemplateDetails _template=@raid/>
|
||||
<RaidTemplateDetails _template=@raid _user=@_user/>
|
||||
}
|
||||
|
||||
|
||||
|
||||
@code
|
||||
{
|
||||
private List<RaidTemplate> _templates;
|
||||
private LiebUser? _user;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
_templates = RaidTemplateService.GetTemplates();
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
|
||||
if (authState.User.Identity.IsAuthenticated)
|
||||
{
|
||||
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
||||
_user = UserService.GetLiebUser(discordId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
|
||||
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
||||
_user = UserService.GetLiebUserSmall(discordId);
|
||||
_user = UserService.GetLiebUserGW2AccountOnly(discordId);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
{
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
||||
_user = UserService.GetLiebUserSmall(discordId);
|
||||
_user = UserService.GetLiebUserGW2AccountOnly(discordId);
|
||||
|
||||
if(!string.IsNullOrEmpty(gw2Id) && int.TryParse(gw2Id, out int parsedId) && _user.GuildWars2Accounts.Where(a => a.GuildWars2AccountId == parsedId).Any())
|
||||
{
|
||||
|
|
|
@ -8,18 +8,17 @@
|
|||
<h3>Role Edit</h3>
|
||||
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin">
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin.Name">
|
||||
<Authorized>
|
||||
|
||||
<table>
|
||||
@foreach(LiebRole role in _roles)
|
||||
{
|
||||
<tr>
|
||||
<td>@if(!role.IsSystemRole)
|
||||
<td>@role.RoleName</td>
|
||||
<td>@if(role.Type == RoleType.UserDefinedRole)
|
||||
{
|
||||
<button type=button @onclick="() => DeleteRoleClicked(role)">Delete Role</button>
|
||||
}</td>
|
||||
<td>@role.RoleName</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
@ -50,9 +49,9 @@
|
|||
LiebRole role = new LiebRole()
|
||||
{
|
||||
RoleName = _newRoleName,
|
||||
IsSystemRole = false,
|
||||
Type = RoleType.UserDefinedRole,
|
||||
Level = 0,
|
||||
LevelToAssign = Constants.RoleLevels.RaidLeadLevel
|
||||
LevelToAssign = Constants.Roles.RaidLead.PowerLevel
|
||||
};
|
||||
await UserService.AddRole(role);
|
||||
_roles = UserService.GetLiebRoles();
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<ValidationSummary />
|
||||
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin" Context="authorizationContext">
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin.Name" Context="authorizationContext">
|
||||
<Authorized>
|
||||
<p>@_submitMessage</p>
|
||||
<p>
|
||||
|
@ -44,21 +44,18 @@
|
|||
<tr>
|
||||
<th></th>
|
||||
<th>Role</th>
|
||||
<th>IsSystemRole</th>
|
||||
<th>Type</th>
|
||||
</tr>
|
||||
@foreach (LiebRole role in _roles)
|
||||
{
|
||||
<tr>
|
||||
@{
|
||||
bool hasRole = _user.RoleAssignments.Where(a => a.LiebRoleId == role.LiebRoleId).Any();
|
||||
bool disabled = _editingUserRights < role.LevelToAssign;
|
||||
bool disabled = _editingUserRights < role.LevelToAssign || role.Type == RoleType.GuildRole;
|
||||
}
|
||||
<td><input type="checkbox" disabled="@disabled" checked="@hasRole" @onchange="args => RoleStatusChanged(role, args)" /></td>
|
||||
<td>@role.RoleName</td>
|
||||
@if(@role.IsSystemRole)
|
||||
{
|
||||
<td>True</td>
|
||||
}
|
||||
<td>@role.Type.ToString()</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<h3>UserOverview</h3>
|
||||
|
||||
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin">
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin.Name">
|
||||
<Authorized>
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="roleedit">
|
||||
|
|
|
@ -47,10 +47,17 @@ builder.Services.AddAuthentication(opt =>
|
|||
|
||||
builder.Services.AddAuthorization(options =>
|
||||
{
|
||||
foreach(string role in Constants.Roles.GetAllRoles())
|
||||
{
|
||||
options.AddPolicy(role, policy => policy.RequireClaim(Constants.ClaimType, role));
|
||||
}
|
||||
options.AddPolicy(Constants.Roles.User.Name, policy => policy.RequireClaim(Constants.ClaimType, new List<string>(){
|
||||
Constants.Roles.User.Name, Constants.Roles.RaidLead.Name, Constants.Roles.Moderator.Name, Constants.Roles.Admin.Name}));
|
||||
|
||||
options.AddPolicy(Constants.Roles.RaidLead.Name, policy => policy.RequireClaim(Constants.ClaimType, new List<string>() {
|
||||
Constants.Roles.RaidLead.Name, Constants.Roles.Moderator.Name, Constants.Roles.Admin.Name }));
|
||||
|
||||
options.AddPolicy(Constants.Roles.Moderator.Name, policy => policy.RequireClaim(Constants.ClaimType, new List<string>() {
|
||||
Constants.Roles.Moderator.Name, Constants.Roles.Admin.Name }));
|
||||
|
||||
options.AddPolicy(Constants.Roles.Admin.Name, policy => policy.RequireClaim(Constants.ClaimType, new List<string>() {
|
||||
Constants.Roles.Admin.Name }));
|
||||
});
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
<span class="oi oi-plus" aria-hidden="true"></span> Raid Overview
|
||||
</NavLink>
|
||||
</div>
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead">
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead.Name">
|
||||
<Authorized>
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="raidtemplateoverview">
|
||||
|
@ -38,7 +38,7 @@
|
|||
</div>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin">
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin.Name">
|
||||
<Authorized>
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="buildoverview">
|
||||
|
@ -56,7 +56,7 @@
|
|||
</div>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin">
|
||||
<AuthorizeView Policy="@Constants.Roles.Admin.Name">
|
||||
<Authorized>
|
||||
<div class="nav-item px-3">
|
||||
<NavLink class="nav-link" href="useroverview">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue