* yavsc.circles.js: js refactoring * Credits.aspx: A credit about to add * CircleBase.cs: The Circle base * NpgsqlCircleProvider.cs: * refactoring * updates the circle * InputCircle.cs: using the new CircleBase class * ResultPages.cs: Using a new "None" attribute * CircleController.cs: refactoring : drops the NewCircle class The `List` method now resterns collection of circlebase * style.css: * a new `dirty` css class, could be used to tag data to validate ala ajax * removed quite all of the `float` usages * AccountController.cs: xml doc * BlogsController.cs: Avatar method moved to the Account controller * YavscHelpers.cs: An avatar url * App.master: Login div moved up * Circles.aspx: a new `private` filed in the `Circle` object, in order to keep circle names from being published as user's information, should be true by default * Profile.aspx: removed the tables * Index.aspx: Un message plus explicite * Web.config: nothing to view * Web.csproj: * new page : Credit * new script: yavsc.circle.js * instdbws.sql: circles are uniques for a given user against a given app * Circle.cs: Now inherits CircleBase to implement a member list * CircleProvider.cs: implements a circle update method * LocalizedText.resx: * LocalizedText.Designer.cs: no content!!! * LocalizedText.fr.resx: * LocalizedText.fr.Designer.cs: pas content * YavscModel.csproj: a new CircleBAse class
138 lines
3.6 KiB
C#
138 lines
3.6 KiB
C#
//
|
|
// CircleController.cs
|
|
//
|
|
// Author:
|
|
// Paul Schneider <paul@pschneider.fr>
|
|
//
|
|
// Copyright (c) 2015 GNU GPL
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
using System;
|
|
using System.Web.Http;
|
|
using Yavsc.Model.RolesAndMembers;
|
|
using System.Collections.Generic;
|
|
using Yavsc.Model.Circles;
|
|
using System.Web.Security;
|
|
using System.Collections.Specialized;
|
|
using Yavsc.Model;
|
|
|
|
namespace Yavsc.ApiControllers
|
|
{
|
|
|
|
/// <summary>
|
|
/// Circle controller.
|
|
/// </summary>
|
|
public class CircleController : ApiController
|
|
{
|
|
|
|
/// <summary>
|
|
/// Create the specified circle.
|
|
/// </summary>
|
|
/// <param name="model">Model.</param>
|
|
[Authorize,
|
|
AcceptVerbs ("POST")]
|
|
public long Create(Circle model)
|
|
{
|
|
string user = Membership.GetUser ().UserName;
|
|
return CircleManager.DefaultProvider.Create (user, model.Title, model.Members);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add the specified users to the circle.
|
|
/// </summary>
|
|
/// <param name="id">Circle Identifier.</param>
|
|
/// <param name="username">username.</param>
|
|
[Authorize,
|
|
AcceptVerbs ("POST")]
|
|
public void Add(long id, string username)
|
|
{
|
|
checkIsOwner (CircleManager.DefaultProvider.Get (id));
|
|
CircleManager.DefaultProvider.AddMember (id, username);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Delete the circle specified by id.
|
|
/// </summary>
|
|
/// <param name="id">Identifier.</param>
|
|
[Authorize,
|
|
AcceptVerbs ("GET")]
|
|
public void Delete(long id)
|
|
{
|
|
checkIsOwner (CircleManager.DefaultProvider.Get (id));
|
|
CircleManager.DefaultProvider.Delete (id);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// Removes the user from circle.
|
|
/// </summary>
|
|
/// <param name="id">Identifier.</param>
|
|
/// <param name="username">Username.</param>
|
|
[Authorize,
|
|
AcceptVerbs ("GET")]
|
|
public void RemoveUserFromCircle(long id, string username)
|
|
{
|
|
checkIsOwner (CircleManager.DefaultProvider.Get(id));
|
|
CircleManager.DefaultProvider.RemoveMembership (id,username);
|
|
}
|
|
|
|
private void checkIsOwner(CircleBase c)
|
|
{
|
|
string user = Membership.GetUser ().UserName;
|
|
if (c.Owner != user)
|
|
throw new AccessViolationException ("You're not owner of this circle");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the circle specified id.
|
|
/// </summary>
|
|
/// <param name="id">Identifier.</param>
|
|
[Authorize,
|
|
AcceptVerbs ("GET")]
|
|
public Circle Get(long id)
|
|
{
|
|
var c = CircleManager.DefaultProvider.GetMembers (id);
|
|
checkIsOwner (c);
|
|
return c;
|
|
}
|
|
|
|
/// <summary>
|
|
/// List the circles
|
|
/// </summary>
|
|
[Authorize,
|
|
AcceptVerbs ("GET")]
|
|
public IEnumerable<CircleBase> List()
|
|
{
|
|
string user = Membership.GetUser ().UserName;
|
|
return CircleManager.DefaultProvider.List (user);
|
|
}
|
|
|
|
/// <summary>
|
|
/// List the circles
|
|
/// </summary>
|
|
[Authorize,
|
|
AcceptVerbs ("POST")]
|
|
public void Update(CircleBase circle)
|
|
{
|
|
string user = Membership.GetUser ().UserName;
|
|
CircleBase current = CircleManager.DefaultProvider.Get (circle.Id);
|
|
if (current.Owner != user)
|
|
throw new AuthorizationDenied ("Your not owner of circle at id "+circle.Id);
|
|
CircleManager.DefaultProvider.UpdateCircle (circle);
|
|
}
|
|
|
|
}
|
|
}
|
|
|