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
|
@ -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,12 +75,14 @@
|
|||
<div>
|
||||
<AuthorizeView>
|
||||
<button class="controlButton raidButton" @onclick="() => SignOffClicked()">Sign Off</button>
|
||||
</AuthorizeView>
|
||||
<AuthorizeView Policy="@Constants.Roles.RaidLead">
|
||||
<button class="controlButton raidButton" @onclick="() => EditClicked()">Edit</button>
|
||||
@if (_raid.RaidType != RaidType.Planned)
|
||||
|
||||
@if (_raid.RaidOwnerId == _user.LiebUserId || _user.RoleAssignments.Max(a => a.LiebRole.Level) >= Constants.RaidEditPowerLevel)
|
||||
{
|
||||
<button class="controlButton raidButton" type=button @onclick="() => RandomizeClicked()">Randomize</button>
|
||||
<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,18 +167,40 @@
|
|||
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);
|
||||
_startTime = await TimeZoneService.GetLocalDateTime(_raid.StartTimeUTC);
|
||||
_endTime = await TimeZoneService.GetLocalDateTime(_raid.EndTimeUTC);
|
||||
_raidDate = _startTime.Date;
|
||||
_freeForAllTime = await TimeZoneService.GetLocalDateTime(_raid.FreeForAllTimeUTC);
|
||||
_freeForAllDate = _freeForAllTime.Date;
|
||||
|
||||
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;
|
||||
_freeForAllTime = await TimeZoneService.GetLocalDateTime(_raid.FreeForAllTimeUTC);
|
||||
_freeForAllDate = _freeForAllTime.Date;
|
||||
}
|
||||
else
|
||||
{
|
||||
_raid = new Raid();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -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,21 +59,27 @@
|
|||
</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>
|
||||
|
||||
@code {
|
||||
[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;
|
||||
|
||||
|
@ -186,19 +189,40 @@
|
|||
private DateTimeOffset _freeForAllDate = DateTime.Now.Date;
|
||||
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);
|
||||
_startTime = _template.StartTime;
|
||||
_endTime = _template.EndTime;
|
||||
_raidDate = _startTime.Date;
|
||||
_freeForAllTime = _template.FreeForAllTime;
|
||||
_freeForAllDate = _freeForAllTime.Date;
|
||||
|
||||
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;
|
||||
_freeForAllTime = _template.FreeForAllTime;
|
||||
_freeForAllDate = _freeForAllTime.Date;
|
||||
}
|
||||
else
|
||||
{
|
||||
_template = new RaidTemplate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -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,20 +8,19 @@
|
|||
<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)
|
||||
{
|
||||
<button type=button @onclick="() => DeleteRoleClicked(role)">Delete Role</button>
|
||||
}</td>
|
||||
<td>@role.RoleName</td>
|
||||
</tr>
|
||||
}
|
||||
<table>
|
||||
@foreach(LiebRole role in _roles)
|
||||
{
|
||||
<tr>
|
||||
<td>@role.RoleName</td>
|
||||
<td>@if(role.Type == RoleType.UserDefinedRole)
|
||||
{
|
||||
<button type=button @onclick="() => DeleteRoleClicked(role)">Delete Role</button>
|
||||
}</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
<p>
|
||||
<label>
|
||||
|
@ -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">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue