Paul Schneider 8 years ago
commit 367b68e093
34 changed files with 396 additions and 67 deletions

@ -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;
}
}
}

@ -11,6 +11,7 @@ namespace Yavsc.Controllers
{
using System;
using Yavsc.Model;
using Yavsc.Models.Messaging;
using Yavsc.Models;
using Yavsc.Models.Booking;
@ -40,10 +41,14 @@ namespace Yavsc.Controllers
var now = DateTime.Now;
var result = _context.Commands.Include(c => c.Location).
Include(c => c.Client).Where(c => c.PerformerId == uid && c.Id < maxId && c.EventDate > now).
Include(c => c.Client).Where(c => c.PerformerId == uid && c.Id < maxId && c.EventDate > now
&& c.ValidationDate == null).
Select(c => new BookQueryProviderInfo
{
Client = new ClientProviderInfo { UserName = c.Client.UserName, UserId = c.ClientId },
Client = new ClientProviderInfo {
UserName = c.Client.UserName,
UserId = c.ClientId,
Avatar = c.Client.Avatar },
Location = c.Location,
EventDate = c.EventDate,
Id = c.Id,

@ -1,10 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc;
using Microsoft.Data.Entity;
using Yavsc.Model;
using Yavsc.Models;
using Yavsc.Models.Messaging;
namespace Yavsc.Controllers
{
@ -20,29 +19,10 @@ namespace Yavsc.Controllers
}
// GET: api/ContactsApi
[HttpGet]
public IEnumerable<ClientProviderInfo> GetClientProviderInfo()
[HttpGet("{id}")]
public ClientProviderInfo GetClientProviderInfo(string id)
{
return _context.ClientProviderInfo;
}
// GET: api/ContactsApi/5
[HttpGet("{id}", Name = "GetClientProviderInfo")]
public IActionResult GetClientProviderInfo([FromRoute] string id)
{
if (!ModelState.IsValid)
{
return HttpBadRequest(ModelState);
}
ClientProviderInfo clientProviderInfo = _context.ClientProviderInfo.Single(m => m.UserId == id);
if (clientProviderInfo == null)
{
return HttpNotFound();
}
return Ok(clientProviderInfo);
return _context.ClientProviderInfo.FirstOrDefault(c=>c.UserId == id);
}
// PUT: api/ContactsApi/5

@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Security.Claims;
using Microsoft.AspNet.Authorization;
@ -124,8 +125,15 @@ namespace Yavsc.Controllers
return HttpBadRequest(ModelState);
}
}
if (estimate.CommandId!=null) {
var query = _context.BookQueries.FirstOrDefault(q => q.Id == estimate.CommandId);
if (query == null || query.PerformerId!= uid)
throw new InvalidOperationException();
query.ValidationDate = DateTime.Now;
}
_context.Estimates.Add(estimate);
/* _context.AttachRange(estimate.Bill);
_context.Attach(estimate);
_context.Entry(estimate).State = EntityState.Added;

@ -175,7 +175,7 @@ namespace Yavsc.Controllers
_siteSettings, _smtpSettings,
command.PerformerProfile.Performer.Email,
yaev.Topic+" "+yaev.Client.UserName,
$"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n"
$"{yaev.Message}\r\n-- \r\n{yaev.Previsional}\r\n{yaev.EventDate}\r\n"
);
}
ViewBag.GoogleSettings = _googleSettings;

@ -0,0 +1,16 @@
using Yavsc.Models.Billing;
namespace Yavsc.Helpers
{
public static class EstimateHelpers {
public static decimal GetTotal(this Estimate estimate)
{
decimal result = 0;
foreach (var l in estimate.Bill)
result += l.Count*l.UnitaryCost;
return result;
}
}
}

@ -1,5 +1,4 @@
using Microsoft.Extensions.Localization;
using Yavsc.Model;
using Yavsc.Models.Booking;
using Yavsc.Models.Messaging;
@ -12,11 +11,15 @@ namespace Yavsc.Helpers
{
var yaev = new BookQueryEvent
{
Client = new ClientProviderInfo { UserName = query.Client.UserName , UserId = query.ClientId } ,
Client = new ClientProviderInfo { 
UserName = query.Client.UserName ,
UserId = query.ClientId,
Avatar = query.Client.Avatar } ,
Previsional = query.Previsional,
EventDate = query.EventDate,
Location = query.Location,
Id = query.Id
Id = query.Id,
Reason = query.Reason
};
return yaev;
}

@ -26,7 +26,7 @@ namespace Yavsc.Helpers
return di;
}
static char[] ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~.".ToCharArray();
static char[] ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_~. ".ToCharArray();
public static bool IsValidDirectoryName(this string name)
{

@ -1,8 +1,8 @@
using System;
using Yavsc.Model;
namespace Yavsc.Interfaces
{
using Yavsc.Models.Messaging;
public interface IBookQueryData
{
ClientProviderInfo Client { get; set; }

@ -2,13 +2,18 @@
public interface IEvent {
/// <summary>
/// An acceptable topic for this event to be.
/// Should return something like the class name
/// of this object
/// <c>/topic/(bookquery|estimate)</c>
/// </summary>
/// <returns></returns>
string Topic { get; set ; }
/// <summary>
/// Should be the user's name
/// </summary>
/// <returns></returns>
string Sender { get; set ; }
/// <summary>
/// The message
/// </summary>
/// <returns></returns>
string Message { get; set; }
}

@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using YavscLib;
namespace Yavsc.Models.Access
{
public class BlackListed: IBlackListed
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; set; }
public string UserId { get; set; }
public string OwnerId { get; set; }
[ForeignKey("OwnerId")]
public virtual ApplicationUser Owner { get; set; }
}
}

@ -12,8 +12,9 @@ using Yavsc.Models.OAuth;
using Yavsc.Models.Workflow;
using Yavsc.Models.Identity;
using Yavsc.Models.Market;
using Yavsc.Model;
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
{

@ -6,6 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema;
using Yavsc.Models.Identity;
using Yavsc.Model.Chat;
using Yavsc.Model.Bank;
using Yavsc.Models.Access;
namespace Yavsc.Models
{
@ -87,5 +88,7 @@ namespace Yavsc.Models
public long DiskQuota { get; set; } = 512*1024*1024;
public long DiskUsage { get; set; } = 0;
public virtual List<BlackListed> BlackList { get; set; }
}
}

@ -2,6 +2,7 @@ using System;
namespace Yavsc.Model
{
using Models.Messaging;
public class BookQueryProviderInfo
{
@ -15,4 +16,5 @@ namespace Yavsc.Model
public string Reason { get; set; }
}
}

@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
namespace Yavsc.Model
namespace Yavsc.Models.Messaging
{
public class ClientProviderInfo
{
@ -8,10 +8,8 @@ namespace Yavsc.Model
public string Avatar { get; set; }
[Key]
public string UserId { get; set; }
public int Rate { get; set; }
public string EMail { get; set; }
public string Phone { get; set; }
public Location BillingAddress { get; set; }
public string ChatHubConnectionId { get; set; }
}
}

@ -0,0 +1,54 @@
using System.Linq;
using Microsoft.Extensions.Localization;
using Yavsc.Helpers;
using Yavsc.Models.Billing;
namespace Yavsc.Models.Messaging
{
public class EstimationEvent: IEvent
{
public EstimationEvent(ApplicationDbContext context, Estimate estimate, IStringLocalizer SR)
{
Estimation = estimate;
var perfer = context.Performers.FirstOrDefault(
p => p.PerformerId == estimate.OwnerId
);
// Use estimate.OwnerId;
ProviderInfo = new ProviderClientInfo {
Rate = perfer.Rate,
UserName = perfer.Performer.UserName,
Avatar = perfer.Performer.Avatar,
UserId = perfer.PerformerId
};
((IEvent)this).Sender = perfer.Performer.UserName;
((IEvent)this).Message = string.Format(SR["EstimationMessageToClient"],perfer.Performer.UserName,
estimate.Title,estimate.GetTotal());
}
ProviderClientInfo ProviderInfo { get; set; }
Estimate Estimation { get; set; }
private string subtopic = null;
string IEvent.Topic
{
get
{
return "/topic/estimate"+subtopic!=null?"/"+subtopic:"";
}
set
{
subtopic = value;
}
}
string IEvent.Sender
{
get; set;
}
string IEvent.Message
{
get; set;
}
}
}

@ -0,0 +1,8 @@
namespace Yavsc.Models.Messaging
{
public class ProviderClientInfo : ClientProviderInfo
{
public int Rate { get; set; }
}
}

@ -203,6 +203,8 @@
<data name="entries"><value>entrées</value></data>
<data name="Estimate"><value>Estimer</value></data>
<data name="Estimate_not_found"><value>Devis non trouvé</value></data>
<data name="EstimationMessageToClient"><value>{0} a validé un devis pour vous : {1}\nAu total : {2} €
Il attend maintenant votre signature.</value></data>
<data name="EstimateWanted"><value>Demande de devis</value></data>
<data name="Event date"><value>Date de l'évennement</value></data>
<data name="EventWebPage"><value>Page web de l'événement</value></data>

@ -8,6 +8,15 @@ namespace Yavsc.Services
{
public interface IGoogleCloudMessageSender
{
Task<MessageWithPayloadResponse> NotifyBookQueryAsync(GoogleAuthSettings googlesettings, IEnumerable<string> registrationId, BookQueryEvent ev);
Task<MessageWithPayloadResponse> NotifyBookQueryAsync(
GoogleAuthSettings googlesettings,
IEnumerable<string> registrationId,
BookQueryEvent ev);
Task<MessageWithPayloadResponse> NotifyEstimateAsync(
GoogleAuthSettings googlesettings,
IEnumerable<string> registrationId,
EstimationEvent ev);
}
}

@ -27,8 +27,7 @@ namespace Yavsc.Services
/// <returns>a MessageWithPayloadResponse,
/// <c>bool somethingsent = (response.failure == 0 &amp;&amp; response.success > 0)</c>
/// </returns>
public async Task<MessageWithPayloadResponse>
NotifyBookQueryAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, BookQueryEvent ev)
public async Task<MessageWithPayloadResponse> NotifyBookQueryAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, BookQueryEvent ev)
{
MessageWithPayloadResponse response = null;
await Task.Run(()=>{
@ -37,6 +36,15 @@ namespace Yavsc.Services
return response;
}
public async Task<MessageWithPayloadResponse> NotifyEstimateAsync(GoogleAuthSettings googleSettings, IEnumerable<string> registrationIds, EstimationEvent ev)
{
MessageWithPayloadResponse response = null;
await Task.Run(()=>{
response = googleSettings.NotifyEvent<EstimationEvent>(registrationIds, ev);
});
return response;
}
public Task<bool> SendEmailAsync(SiteSettings siteSettings, SmtpSettings smtpSettings, string email, string subject, string message)
{
try

@ -22,7 +22,7 @@ namespace Yavsc.ViewModels.UserFiles
var finalPath = (path==null) ? username : username + Path.DirectorySeparatorChar + path;
if ( !finalPath.IsValidPath() )
throw new InvalidOperationException(
$"File name contains invalid chars, using path {SubPath}");
$"File name contains invalid chars, using path {finalPath}");
dInfo = new DirectoryInfo(
Path.Combine(Startup.UserFilesDirName,finalPath));

@ -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 :

@ -4,7 +4,6 @@
{
long ContactCredits { get; set; }
decimal Credits { get; set; }
IApplicationUser Owner { get; set; }
string UserId { get; set; }
}
}

@ -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
{
IApplicationUser Author { get; set; }
string AuthorId { get; set; }
string bcontent { get; set; }
string Content { get; set; }
long Id { get; set; }
DateTime modified { get; set; }
string photo { get; set; }
DateTime posted { get; set; }
int rate { get; set; }
string title { get; set; }
bool visible { get; set; }
DateTime Modified { get; set; }
string Photo { get; set; }
DateTime Posted { get; set; }
int Rate { get; set; }
string Title { get; set; }
bool Visible { get; set; }
}
}

@ -1,7 +1,5 @@
using System.Resources;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information

@ -57,6 +57,7 @@
</ItemGroup>
<ItemGroup>
<Content Include="project.json" />
<Content Include="IBlackListed.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">

@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# 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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

@ -15,6 +15,13 @@
"dependencies": {},
"frameworks": {
"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,
"targets": {
".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": {},
"projectFileDependencyGroups": {
"": [],
".NETFramework,Version=v4.5.1": [],
".NETPortable,Version=v4.5,Profile=Profile111": []
},
"tools": {},
"projectFileToolGroups": {}
".NETPortable,Version=v4.5,Profile=Profile111": [
"fx/System.Runtime >= 4.0.0",
"fx/System.Globalization >= 4.0.0",
"fx/System.Resources.ResourceManager >= 4.0.0",
"fx/System.Resources.Reader >= 4.0.0"
]
}
}
Loading…