blacklisting + refactoring
This commit is contained in:
parent
cf5725daaf
commit
67afd19d32
16 changed files with 235 additions and 24 deletions
165
Yavsc/ApiControllers/BlackListApiController.cs
Normal file
165
Yavsc/ApiControllers/BlackListApiController.cs
Normal file
|
|
@ -0,0 +1,165 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNet.Authorization;
|
||||
using Microsoft.AspNet.Http;
|
||||
using Microsoft.AspNet.Mvc;
|
||||
using Microsoft.Data.Entity;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Access;
|
||||
|
||||
namespace Yavsc.Controllers
|
||||
{
|
||||
[Produces("application/json")]
|
||||
[Route("api/blacklist"), Authorize]
|
||||
public class BlackListApiController : Controller
|
||||
{
|
||||
private ApplicationDbContext _context;
|
||||
|
||||
public BlackListApiController(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
// GET: api/BlackListApi
|
||||
[HttpGet]
|
||||
public IEnumerable<BlackListed> GetBlackListed()
|
||||
{
|
||||
return _context.BlackListed;
|
||||
}
|
||||
|
||||
// GET: api/BlackListApi/5
|
||||
[HttpGet("{id}", Name = "GetBlackListed")]
|
||||
public IActionResult GetBlackListed([FromRoute] long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
BlackListed blackListed = _context.BlackListed.Single(m => m.Id == id);
|
||||
if (blackListed == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
if (!CheckPermission(blackListed))
|
||||
return HttpBadRequest();
|
||||
|
||||
return Ok(blackListed);
|
||||
}
|
||||
|
||||
private bool CheckPermission(BlackListed blackListed)
|
||||
{
|
||||
var uid = User.GetUserId();
|
||||
if (uid != blackListed.OwnerId)
|
||||
if (!User.IsInRole(Constants.AdminGroupName))
|
||||
if (!User.IsInRole(Constants.FrontOfficeGroupName))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// PUT: api/BlackListApi/5
|
||||
[HttpPut("{id}")]
|
||||
public IActionResult PutBlackListed(long id, [FromBody] BlackListed blackListed)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (id != blackListed.Id)
|
||||
{
|
||||
return HttpBadRequest();
|
||||
}
|
||||
if (!CheckPermission(blackListed))
|
||||
return HttpBadRequest();
|
||||
_context.Entry(blackListed).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!BlackListedExists(id))
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpStatusCodeResult(StatusCodes.Status204NoContent);
|
||||
}
|
||||
|
||||
// POST: api/BlackListApi
|
||||
[HttpPost]
|
||||
public IActionResult PostBlackListed([FromBody] BlackListed blackListed)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
if (!CheckPermission(blackListed))
|
||||
return HttpBadRequest();
|
||||
|
||||
_context.BlackListed.Add(blackListed);
|
||||
try
|
||||
{
|
||||
_context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
if (BlackListedExists(blackListed.Id))
|
||||
{
|
||||
return new HttpStatusCodeResult(StatusCodes.Status409Conflict);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return CreatedAtRoute("GetBlackListed", new { id = blackListed.Id }, blackListed);
|
||||
}
|
||||
|
||||
// DELETE: api/BlackListApi/5
|
||||
[HttpDelete("{id}")]
|
||||
public IActionResult DeleteBlackListed(long id)
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return HttpBadRequest(ModelState);
|
||||
}
|
||||
|
||||
BlackListed blackListed = _context.BlackListed.Single(m => m.Id == id);
|
||||
if (blackListed == null)
|
||||
{
|
||||
return HttpNotFound();
|
||||
}
|
||||
|
||||
if (!CheckPermission(blackListed))
|
||||
return HttpBadRequest();
|
||||
|
||||
_context.BlackListed.Remove(blackListed);
|
||||
_context.SaveChanges();
|
||||
|
||||
return Ok(blackListed);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private bool BlackListedExists(long id)
|
||||
{
|
||||
return _context.BlackListed.Count(e => e.Id == id) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,14 +1,15 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using YavscLib;
|
||||
|
||||
namespace Yavsc.Models.Access
|
||||
{
|
||||
public class BlackListed
|
||||
public class BlackListed: IBlackListed
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public long Id { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public long OwnerId { get; set; }
|
||||
public string OwnerId { get; set; }
|
||||
|
||||
[ForeignKey("OwnerId")]
|
||||
public virtual ApplicationUser Owner { get; set; }
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ using Yavsc.Models.Identity;
|
|||
using Yavsc.Models.Market;
|
||||
using Yavsc.Model.Chat;
|
||||
using Yavsc.Models.Messaging;
|
||||
using Yavsc.Models.Access;
|
||||
|
||||
namespace Yavsc.Models
|
||||
{
|
||||
|
|
@ -189,6 +190,8 @@ namespace Yavsc.Models
|
|||
public DbSet<ClientProviderInfo> ClientProviderInfo { get; set; }
|
||||
|
||||
public DbSet<Connection> Connections { get; set; }
|
||||
|
||||
public DbSet<BlackListed> BlackListed { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||
|
||||
namespace Yavsc.Models
|
||||
{
|
||||
using Interfaces;
|
||||
|
||||
public partial class AccountBalance: IAccountBalance {
|
||||
[Key]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Newtonsoft.Json;
|
||||
using Yavsc.Interfaces;
|
||||
|
||||
namespace Yavsc.Models
|
||||
{
|
||||
|
|
|
|||
|
|
@ -105,7 +105,8 @@
|
|||
"Microsoft.AspNet.Authentication.OAuth": "1.0.0-rc1-final",
|
||||
"Microsoft.AspNet.Mvc.Formatters.Json": "6.0.0-rc1-final",
|
||||
"Microsoft.AspNet.OWin": "1.0.0-rc1-final",
|
||||
"System.Json": "4.0.20126.16343"
|
||||
"System.Json": "4.0.20126.16343",
|
||||
"YavscLib": "1.0.0-*"
|
||||
},
|
||||
"commands": {
|
||||
"web": "Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000",
|
||||
|
|
|
|||
|
|
@ -2809,6 +2809,10 @@
|
|||
"lib/WebGrease.dll": {}
|
||||
}
|
||||
},
|
||||
"YavscLib/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETFramework,Version=v4.5.1"
|
||||
},
|
||||
"Zlib.Portable.Signed/1.11.0": {
|
||||
"type": "package",
|
||||
"compile": {
|
||||
|
|
@ -5626,6 +5630,10 @@
|
|||
"lib/WebGrease.dll": {}
|
||||
}
|
||||
},
|
||||
"YavscLib/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETFramework,Version=v4.5.1"
|
||||
},
|
||||
"Zlib.Portable.Signed/1.11.0": {
|
||||
"type": "package",
|
||||
"compile": {
|
||||
|
|
@ -8443,6 +8451,10 @@
|
|||
"lib/WebGrease.dll": {}
|
||||
}
|
||||
},
|
||||
"YavscLib/1.0.0": {
|
||||
"type": "project",
|
||||
"framework": ".NETFramework,Version=v4.5.1"
|
||||
},
|
||||
"Zlib.Portable.Signed/1.11.0": {
|
||||
"type": "package",
|
||||
"compile": {
|
||||
|
|
@ -8455,6 +8467,10 @@
|
|||
}
|
||||
},
|
||||
"libraries": {
|
||||
"YavscLib/1.0.0": {
|
||||
"type": "project",
|
||||
"path": "../YavscLib/project.json"
|
||||
},
|
||||
"Antlr/3.4.1.9004": {
|
||||
"type": "package",
|
||||
"sha512": "c1S+HBE+KYA5EBxtn25LEK02hHPH/tDQ6RviUTTCJpZIPoputtn8ArsQJy9lVJWZOnw37ufByO2Fmf1M8wpr8Q==",
|
||||
|
|
@ -11421,7 +11437,8 @@
|
|||
"Microsoft.AspNet.Authentication.OAuth >= 1.0.0-rc1-final",
|
||||
"Microsoft.AspNet.Mvc.Formatters.Json >= 6.0.0-rc1-final",
|
||||
"Microsoft.AspNet.OWin >= 1.0.0-rc1-final",
|
||||
"System.Json >= 4.0.20126.16343"
|
||||
"System.Json >= 4.0.20126.16343",
|
||||
"YavscLib >= 1.0.0-*"
|
||||
],
|
||||
"DNX,Version=v4.5.1": [
|
||||
"fx/System.Drawing >= 4.0.0"
|
||||
|
|
|
|||
|
|
@ -77,6 +77,12 @@ Ceci est une grosse liste de fonctionnalités, existantes, ou à implémenter, o
|
|||
☐ Podcasts.
|
||||
☐ Personalisation des blogs.
|
||||
☐ Monétarisations.
|
||||
☐ Distribution de gold card (illimité), de carte vertes (à durée fixe),
|
||||
de la part d'un prestataire, donnant accès au destinataire au chat privé.
|
||||
☐ La carte blanche: en la confiant, le prestataire délègue la gestion de son agenda à un autre utilisateur,
|
||||
elle implique le droit au chat privé
|
||||
☐ de badges temporaires, donnant accès à un téléchargement unique et limité dans le temps, d'un seul fichier,
|
||||
sans autre forme d'autorisation.
|
||||
|
||||
### Réécritures prévues :
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue