refact
This commit is contained in:
parent
1aafb7cc7d
commit
e24208e77b
32 changed files with 96 additions and 94 deletions
|
|
@ -27,12 +27,12 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
bool UserIsAdminOrThis(string uid)
|
||||
{
|
||||
if (User.IsInRole(Constants.AdminGroupName)) return true;
|
||||
if (User.IsInRole(YavscConstants.AdminGroupName)) return true;
|
||||
return uid == User.GetUserId();
|
||||
}
|
||||
bool UserIsAdminOrInThese(string oid, string uid)
|
||||
{
|
||||
if (User.IsInRole(Constants.AdminGroupName)) return true;
|
||||
if (User.IsInRole(YavscConstants.AdminGroupName)) return true;
|
||||
var cuid = User.GetUserId();
|
||||
return cuid == uid || cuid == oid;
|
||||
}
|
||||
|
|
@ -82,7 +82,7 @@ namespace Yavsc.Controllers
|
|||
return BadRequest();
|
||||
}
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||
{
|
||||
if (uid != estimate.OwnerId)
|
||||
{
|
||||
|
|
@ -118,7 +118,7 @@ namespace Yavsc.Controllers
|
|||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (estimate.OwnerId == null) estimate.OwnerId = uid;
|
||||
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||
{
|
||||
if (uid != estimate.OwnerId)
|
||||
{
|
||||
|
|
@ -187,7 +187,7 @@ namespace Yavsc.Controllers
|
|||
return NotFound();
|
||||
}
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||
{
|
||||
if (uid != estimate.OwnerId)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (estimateTemplate.OwnerId!=uid)
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||
return new StatusCodeResult(StatusCodes.Status403Forbidden);
|
||||
|
||||
_context.Entry(estimateTemplate).State = EntityState.Modified;
|
||||
|
|
@ -132,7 +132,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (estimateTemplate.OwnerId!=uid)
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||
return new StatusCodeResult(StatusCodes.Status403Forbidden);
|
||||
|
||||
_context.EstimateTemplates.Remove(estimateTemplate);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
// PUT: api/ProductApi/5
|
||||
[HttpPut("{id}"),Authorize(Constants.FrontOfficeGroupName)]
|
||||
[HttpPut("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||
public IActionResult PutProduct(long id, [FromBody] Product product)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
|
|
@ -81,7 +81,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
// POST: api/ProductApi
|
||||
[HttpPost,Authorize(Constants.FrontOfficeGroupName)]
|
||||
[HttpPost,Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||
public IActionResult PostProduct([FromBody] Product product)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
|
|
@ -110,7 +110,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
// DELETE: api/ProductApi/5
|
||||
[HttpDelete("{id}"),Authorize(Constants.FrontOfficeGroupName)]
|
||||
[HttpDelete("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||
public IActionResult DeleteProduct(long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (blogpost.AuthorId!=uid)
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||
return BadRequest();
|
||||
|
||||
_context.SaveChanges(User.GetUserId());
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ namespace Yavsc.Controllers
|
|||
{
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (uid != blackListed.OwnerId)
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
if (!User.IsInRole(Constants.FrontOfficeGroupName))
|
||||
if (!User.IsInRole(YavscConstants.AdminGroupName))
|
||||
if (!User.IsInRole(YavscConstants.FrontOfficeGroupName))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (uid != chatRoomAccess.UserId && uid != chatRoomAccess.Room.OwnerId
|
||||
&& ! User.IsInMsRole(Constants.AdminGroupName))
|
||||
&& ! User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
|
||||
{
|
||||
ModelState.AddModelError("UserId","get refused");
|
||||
|
|
@ -72,7 +72,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
|
||||
|
||||
if (uid != room.OwnerId && ! User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (uid != room.OwnerId && ! User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
{
|
||||
ModelState.AddModelError("ChannelName", "access put refused");
|
||||
return BadRequest(ModelState);
|
||||
|
|
@ -110,7 +110,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
|
||||
if (room == null || (uid != room.OwnerId && ! User.IsInMsRole(Constants.AdminGroupName)))
|
||||
if (room == null || (uid != room.OwnerId && ! User.IsInMsRole(YavscConstants.AdminGroupName)))
|
||||
{
|
||||
ModelState.AddModelError("ChannelName", "access post refused");
|
||||
return BadRequest(ModelState);
|
||||
|
|
@ -154,7 +154,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
|
||||
if (room == null || (uid != room.OwnerId && chatRoomAccess.UserId != uid && ! User.IsInMsRole(Constants.AdminGroupName)))
|
||||
if (room == null || (uid != room.OwnerId && chatRoomAccess.UserId != uid && ! User.IsInMsRole(YavscConstants.AdminGroupName)))
|
||||
{
|
||||
ModelState.AddModelError("UserId", "access drop refused");
|
||||
return BadRequest(ModelState);
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ namespace Yavsc.Controllers
|
|||
|
||||
if (User.GetUserId() != chatRoom.OwnerId )
|
||||
{
|
||||
if (!User.IsInMsRole(Constants.AdminGroupName))
|
||||
if (!User.IsInMsRole(YavscConstants.AdminGroupName))
|
||||
return BadRequest(new {error = "OwnerId"});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
// PUT: api/ServiceApi/5
|
||||
[HttpPut("{id}"),Authorize(Constants.FrontOfficeGroupName)]
|
||||
[HttpPut("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||
public IActionResult PutService(long id, [FromBody] Service service)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
|
|
@ -81,7 +81,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
// POST: api/ServiceApi
|
||||
[HttpPost,Authorize(Constants.FrontOfficeGroupName)]
|
||||
[HttpPost,Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||
public IActionResult PostService([FromBody] Service service)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
|
|
@ -110,7 +110,7 @@ namespace Yavsc.Controllers
|
|||
}
|
||||
|
||||
// DELETE: api/ServiceApi/5
|
||||
[HttpDelete("{id}"),Authorize(Constants.FrontOfficeGroupName)]
|
||||
[HttpDelete("{id}"),Authorize(YavscConstants.FrontOfficeGroupName)]
|
||||
public IActionResult DeleteService(long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue