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;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using YavscLib;
|
||||||
|
|
||||||
namespace Yavsc.Models.Access
|
namespace Yavsc.Models.Access
|
||||||
{
|
{
|
||||||
public class BlackListed
|
public class BlackListed: IBlackListed
|
||||||
{
|
{
|
||||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
public string UserId { get; set; }
|
public string UserId { get; set; }
|
||||||
public long OwnerId { get; set; }
|
public string OwnerId { get; set; }
|
||||||
|
|
||||||
[ForeignKey("OwnerId")]
|
[ForeignKey("OwnerId")]
|
||||||
public virtual ApplicationUser Owner { get; set; }
|
public virtual ApplicationUser Owner { get; set; }
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ using Yavsc.Models.Identity;
|
||||||
using Yavsc.Models.Market;
|
using Yavsc.Models.Market;
|
||||||
using Yavsc.Model.Chat;
|
using Yavsc.Model.Chat;
|
||||||
using Yavsc.Models.Messaging;
|
using Yavsc.Models.Messaging;
|
||||||
|
using Yavsc.Models.Access;
|
||||||
|
|
||||||
namespace Yavsc.Models
|
namespace Yavsc.Models
|
||||||
{
|
{
|
||||||
|
|
@ -189,6 +190,8 @@ namespace Yavsc.Models
|
||||||
public DbSet<ClientProviderInfo> ClientProviderInfo { get; set; }
|
public DbSet<ClientProviderInfo> ClientProviderInfo { get; set; }
|
||||||
|
|
||||||
public DbSet<Connection> Connections { 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
|
namespace Yavsc.Models
|
||||||
{
|
{
|
||||||
using Interfaces;
|
|
||||||
|
|
||||||
public partial class AccountBalance: IAccountBalance {
|
public partial class AccountBalance: IAccountBalance {
|
||||||
[Key]
|
[Key]
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ using System;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Yavsc.Interfaces;
|
|
||||||
|
|
||||||
namespace Yavsc.Models
|
namespace Yavsc.Models
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -105,7 +105,8 @@
|
||||||
"Microsoft.AspNet.Authentication.OAuth": "1.0.0-rc1-final",
|
"Microsoft.AspNet.Authentication.OAuth": "1.0.0-rc1-final",
|
||||||
"Microsoft.AspNet.Mvc.Formatters.Json": "6.0.0-rc1-final",
|
"Microsoft.AspNet.Mvc.Formatters.Json": "6.0.0-rc1-final",
|
||||||
"Microsoft.AspNet.OWin": "1.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": {
|
"commands": {
|
||||||
"web": "Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000",
|
"web": "Microsoft.AspNet.Server.Kestrel --server.urls http://*:5000",
|
||||||
|
|
|
||||||
|
|
@ -2809,6 +2809,10 @@
|
||||||
"lib/WebGrease.dll": {}
|
"lib/WebGrease.dll": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"YavscLib/1.0.0": {
|
||||||
|
"type": "project",
|
||||||
|
"framework": ".NETFramework,Version=v4.5.1"
|
||||||
|
},
|
||||||
"Zlib.Portable.Signed/1.11.0": {
|
"Zlib.Portable.Signed/1.11.0": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"compile": {
|
"compile": {
|
||||||
|
|
@ -5626,6 +5630,10 @@
|
||||||
"lib/WebGrease.dll": {}
|
"lib/WebGrease.dll": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"YavscLib/1.0.0": {
|
||||||
|
"type": "project",
|
||||||
|
"framework": ".NETFramework,Version=v4.5.1"
|
||||||
|
},
|
||||||
"Zlib.Portable.Signed/1.11.0": {
|
"Zlib.Portable.Signed/1.11.0": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"compile": {
|
"compile": {
|
||||||
|
|
@ -8443,6 +8451,10 @@
|
||||||
"lib/WebGrease.dll": {}
|
"lib/WebGrease.dll": {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"YavscLib/1.0.0": {
|
||||||
|
"type": "project",
|
||||||
|
"framework": ".NETFramework,Version=v4.5.1"
|
||||||
|
},
|
||||||
"Zlib.Portable.Signed/1.11.0": {
|
"Zlib.Portable.Signed/1.11.0": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"compile": {
|
"compile": {
|
||||||
|
|
@ -8455,6 +8467,10 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"libraries": {
|
"libraries": {
|
||||||
|
"YavscLib/1.0.0": {
|
||||||
|
"type": "project",
|
||||||
|
"path": "../YavscLib/project.json"
|
||||||
|
},
|
||||||
"Antlr/3.4.1.9004": {
|
"Antlr/3.4.1.9004": {
|
||||||
"type": "package",
|
"type": "package",
|
||||||
"sha512": "c1S+HBE+KYA5EBxtn25LEK02hHPH/tDQ6RviUTTCJpZIPoputtn8ArsQJy9lVJWZOnw37ufByO2Fmf1M8wpr8Q==",
|
"sha512": "c1S+HBE+KYA5EBxtn25LEK02hHPH/tDQ6RviUTTCJpZIPoputtn8ArsQJy9lVJWZOnw37ufByO2Fmf1M8wpr8Q==",
|
||||||
|
|
@ -11421,7 +11437,8 @@
|
||||||
"Microsoft.AspNet.Authentication.OAuth >= 1.0.0-rc1-final",
|
"Microsoft.AspNet.Authentication.OAuth >= 1.0.0-rc1-final",
|
||||||
"Microsoft.AspNet.Mvc.Formatters.Json >= 6.0.0-rc1-final",
|
"Microsoft.AspNet.Mvc.Formatters.Json >= 6.0.0-rc1-final",
|
||||||
"Microsoft.AspNet.OWin >= 1.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": [
|
"DNX,Version=v4.5.1": [
|
||||||
"fx/System.Drawing >= 4.0.0"
|
"fx/System.Drawing >= 4.0.0"
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,12 @@ Ceci est une grosse liste de fonctionnalités, existantes, ou à implémenter, o
|
||||||
☐ Podcasts.
|
☐ Podcasts.
|
||||||
☐ Personalisation des blogs.
|
☐ Personalisation des blogs.
|
||||||
☐ Monétarisations.
|
☐ 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 :
|
### Réécritures prévues :
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
{
|
{
|
||||||
long ContactCredits { get; set; }
|
long ContactCredits { get; set; }
|
||||||
decimal Credits { get; set; }
|
decimal Credits { get; set; }
|
||||||
IApplicationUser Owner { get; set; }
|
|
||||||
string UserId { get; set; }
|
string UserId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
9
YavscLib/IBlackListed.cs
Normal file
9
YavscLib/IBlackListed.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
namespace YavscLib
|
||||||
|
{
|
||||||
|
public interface IBlackListed
|
||||||
|
{
|
||||||
|
long Id { get; set; }
|
||||||
|
string UserId { get; set; }
|
||||||
|
string OwnerId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,15 +4,14 @@ namespace Yavsc.Models
|
||||||
{
|
{
|
||||||
public interface IBlog
|
public interface IBlog
|
||||||
{
|
{
|
||||||
IApplicationUser Author { get; set; }
|
|
||||||
string AuthorId { get; set; }
|
string AuthorId { get; set; }
|
||||||
string bcontent { get; set; }
|
string Content { get; set; }
|
||||||
long Id { get; set; }
|
long Id { get; set; }
|
||||||
DateTime modified { get; set; }
|
DateTime Modified { get; set; }
|
||||||
string photo { get; set; }
|
string Photo { get; set; }
|
||||||
DateTime posted { get; set; }
|
DateTime Posted { get; set; }
|
||||||
int rate { get; set; }
|
int Rate { get; set; }
|
||||||
string title { get; set; }
|
string Title { get; set; }
|
||||||
bool visible { get; set; }
|
bool Visible { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
using System.Resources;
|
using System.Resources;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
// General Information about an assembly is controlled through the following
|
// General Information about an assembly is controlled through the following
|
||||||
// set of attributes. Change these attribute values to modify the information
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="project.json" />
|
<Content Include="project.json" />
|
||||||
|
<Content Include="IBlackListed.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2012
|
# Visual Studio 2012
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Yavsc.Client", "Yavsc.Client.csproj", "{67F9D3A8-F71E-4428-913F-C37AE82CDB24}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YavscLib", "YavscLib.csproj", "{67F9D3A8-F71E-4428-913F-C37AE82CDB24}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,13 @@
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"net451": {},
|
"net451": {},
|
||||||
".NETPortable,Version=v4.5,Profile=Profile111": {}
|
".NETPortable,Version=v4.5,Profile=Profile111": {
|
||||||
|
"frameworkAssemblies": {
|
||||||
|
"System.Runtime": "4.0.0",
|
||||||
|
"System.Globalization": "4.0.0",
|
||||||
|
"System.Resources.ResourceManager": "4.0.0",
|
||||||
|
"System.Resources.Reader": "4.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -3,14 +3,21 @@
|
||||||
"version": 2,
|
"version": 2,
|
||||||
"targets": {
|
"targets": {
|
||||||
".NETFramework,Version=v4.5.1": {},
|
".NETFramework,Version=v4.5.1": {},
|
||||||
".NETPortable,Version=v4.5,Profile=Profile111": {}
|
".NETPortable,Version=v4.5,Profile=Profile111": {},
|
||||||
|
".NETFramework,Version=v4.5.1/debian.8-x86": {},
|
||||||
|
".NETFramework,Version=v4.5.1/debian.8-x64": {},
|
||||||
|
".NETPortable,Version=v4.5,Profile=Profile111/debian.8-x86": {},
|
||||||
|
".NETPortable,Version=v4.5,Profile=Profile111/debian.8-x64": {}
|
||||||
},
|
},
|
||||||
"libraries": {},
|
"libraries": {},
|
||||||
"projectFileDependencyGroups": {
|
"projectFileDependencyGroups": {
|
||||||
"": [],
|
"": [],
|
||||||
".NETFramework,Version=v4.5.1": [],
|
".NETFramework,Version=v4.5.1": [],
|
||||||
".NETPortable,Version=v4.5,Profile=Profile111": []
|
".NETPortable,Version=v4.5,Profile=Profile111": [
|
||||||
},
|
"fx/System.Runtime >= 4.0.0",
|
||||||
"tools": {},
|
"fx/System.Globalization >= 4.0.0",
|
||||||
"projectFileToolGroups": {}
|
"fx/System.Resources.ResourceManager >= 4.0.0",
|
||||||
|
"fx/System.Resources.Reader >= 4.0.0"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue