Bug fix - notifications audience
* Performers had their notifications publicaly published. * refacto admin group name
This commit is contained in:
parent
d192705f29
commit
d476c08046
36 changed files with 421 additions and 74 deletions
|
|
@ -56,7 +56,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
// ensure all roles existence
|
||||
foreach (string roleName in new string[] {
|
||||
Constants.AdminGroupName,
|
||||
Constants.AdminName,
|
||||
Constants.StarGroupName,
|
||||
Constants.PerformerGroupName,
|
||||
Constants.FrontOfficeGroupName,
|
||||
|
|
@ -86,13 +86,12 @@ namespace Yavsc.Controllers
|
|||
public async Task<IActionResult> Take()
|
||||
{
|
||||
// If some amdin already exists, make this method disapear
|
||||
var admins = await _userManager.GetUsersInRoleAsync(Constants.AdminGroupName);
|
||||
var admins = await _userManager.GetUsersInRoleAsync(Constants.AdminName);
|
||||
if (admins != null && admins.Count > 0)
|
||||
{
|
||||
// All is ok, nothing to do here.
|
||||
if (User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (User.IsInMsRole(Constants.AdminName))
|
||||
{
|
||||
|
||||
return Ok(new { message = "you already got it." });
|
||||
}
|
||||
return NotFound();
|
||||
|
|
@ -116,7 +115,7 @@ namespace Yavsc.Controllers
|
|||
return new BadRequestObjectResult(ModelState);
|
||||
}
|
||||
|
||||
var addToRoleResult = await _userManager.AddToRoleAsync(user, Constants.AdminGroupName);
|
||||
var addToRoleResult = await _userManager.AddToRoleAsync(user, Constants.AdminName);
|
||||
if (!addToRoleResult.Succeeded)
|
||||
{
|
||||
AddErrors(addToRoleResult);
|
||||
|
|
@ -130,11 +129,11 @@ namespace Yavsc.Controllers
|
|||
public async Task<IActionResult> Index()
|
||||
{
|
||||
var adminCount = await _userManager.GetUsersInRoleAsync(
|
||||
Constants.AdminGroupName);
|
||||
Constants.AdminName);
|
||||
var userCount = await _dbContext.Users.CountAsync();
|
||||
var youAreAdmin = await _userManager.IsInRoleAsync(
|
||||
await _userManager.FindByIdAsync(User.GetUserId()),
|
||||
Constants.AdminGroupName);
|
||||
Constants.AdminName);
|
||||
|
||||
var roles = await _roleManager.Roles.Select(x => new RoleInfo
|
||||
{
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
private async Task SetupView(Announce announce)
|
||||
{
|
||||
ViewBag.IsAdmin = User.IsInMsRole(Constants.AdminGroupName);
|
||||
ViewBag.IsAdmin = User.IsInMsRole(Constants.AdminName);
|
||||
ViewBag.IsPerformer = User.IsInMsRole(Constants.PerformerGroupName);
|
||||
ViewBag.AllowEdit = announce==null || announce.Id<=0 || !_authorizationService.AuthorizeAsync(User,announce,new EditPermission()).IsFaulted;
|
||||
List<SelectListItem> dl = new List<SelectListItem>();
|
||||
|
|
@ -80,7 +80,7 @@ namespace Yavsc.Controllers
|
|||
if (ModelState.IsValid)
|
||||
{
|
||||
// Only allow admin to create corporate annonces
|
||||
if (announce.For == Reason.Corporate && ! User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (announce.For == Reason.Corporate && ! User.IsInMsRole(Constants.AdminName))
|
||||
{
|
||||
ModelState.AddModelError("For", _localizer["YourNotAdmin"]);
|
||||
return View(announce);
|
||||
|
|
|
|||
|
|
@ -50,9 +50,14 @@ namespace Yavsc.Controllers
|
|||
if (clicked == null) clicked = new long[0];
|
||||
}
|
||||
else clicked = _dbContext.DismissClicked.Where(d => d.UserId == uid).Select(d => d.NotificationId).ToArray();
|
||||
var isAdmin = User.IsInRole(Constants.AdminName);
|
||||
var notes = _dbContext.Notification.Where(
|
||||
n => !clicked.Contains(n.Id)
|
||||
);
|
||||
).Where(n =>
|
||||
string.IsNullOrWhiteSpace(n.Target)
|
||||
|| (n.Target != null && n.Target.StartsWith("pub/"))
|
||||
|| (!string.IsNullOrWhiteSpace(uid) && n.Target == $"user/{uid}")
|
||||
|| (isAdmin && n.Target == Constants.Administration));
|
||||
if (notes.Any()) this.Notify(notes);
|
||||
|
||||
var toShow = _dbContext.Activities
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ namespace Yavsc.Controllers
|
|||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
if (model.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (model.UserId != uid) if (!User.IsInMsRole(Constants.AdminName))
|
||||
return new ChallengeResult();
|
||||
|
||||
_context.Instrumentation.Add(model);
|
||||
|
|
@ -81,7 +81,7 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
return NotFound();
|
||||
}
|
||||
if (id != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (id != uid) if (!User.IsInMsRole(Constants.AdminName))
|
||||
return new ChallengeResult();
|
||||
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
|
||||
if (musicianSettings == null)
|
||||
|
|
@ -97,7 +97,7 @@ namespace Yavsc.Controllers
|
|||
public async Task<IActionResult> Edit(Instrumentation musicianSettings)
|
||||
{
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminName))
|
||||
return new ChallengeResult();
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
|
|
@ -123,7 +123,7 @@ namespace Yavsc.Controllers
|
|||
return NotFound();
|
||||
}
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminName))
|
||||
return new ChallengeResult();
|
||||
return View(musicianSettings);
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ namespace Yavsc.Controllers
|
|||
Instrumentation musicianSettings = await _context.Instrumentation.SingleAsync(m => m.UserId == id);
|
||||
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (musicianSettings.UserId != uid) if (!User.IsInMsRole(Constants.AdminName))
|
||||
return new ChallengeResult();
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -263,14 +263,14 @@ public static class HostingExtensions
|
|||
policy
|
||||
.RequireAuthenticatedUser()
|
||||
.RequireClaim(Constants.RoleClaimType,
|
||||
new string[] { Constants.PerformerGroupName, Constants.AdminGroupName })
|
||||
new string[] { Constants.PerformerGroupName, Constants.AdminName })
|
||||
;
|
||||
});
|
||||
options.AddPolicy("AdministratorOnly", policy =>
|
||||
{
|
||||
_ = policy
|
||||
.RequireAuthenticatedUser()
|
||||
.RequireClaim(Constants.RoleClaimType, Constants.AdminGroupName);
|
||||
.RequireClaim(Constants.RoleClaimType, Constants.AdminName);
|
||||
});
|
||||
|
||||
options.AddPolicy("FrontOffice", policy => policy.RequireRole(Constants.FrontOfficeGroupName));
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
<li><a class="dropdown-item @PageHelpers.ActivePage(ViewContext, "Feature")" asp-controller="Feature" asp-action="Index">Features</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
@if (User.IsInMsRole(Constants.AdminGroupName)) {
|
||||
@if (User.IsInMsRole(Constants.AdminName)) {
|
||||
<li class="nav-item dropdown">
|
||||
<a class="nav-link dropdown-toggle @PageHelpers.ActivePageAny(ViewContext, administrationControllers)" href="#" id="dropdown05" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Administration
|
||||
|
|
|
|||
Loading…
Reference in a new issue