* T.cs: * IModule.cs: * App.master: * IProvider.cs: * Error.aspx: * AOEMail.aspx: * Login.aspx: * Index.aspx: * Admin.aspx: * yavscModel.csproj: * WFManager.cs: * Index.aspx: * AddRole.aspx: * Profile.aspx: * Edit.aspx: * Register.aspx: * Index.aspx: * RoleList.aspx: * UserList.aspx: * Validate.aspx: * RemovePost.aspx: * Index.aspx: * BasketImpact.cs: * Brand.aspx: * Delete.aspx: * Create.aspx: * Backups.aspx: * HomeController.cs: * BlogManager.cs: * Restore.aspx: * Details.aspx: * TitleNotFound.aspx: * Product.aspx: * AdminController.cs: * Command.aspx: * Service.aspx: * BlogProvider.cs: * NewProject.aspx: * Catalog.aspx: * Restored.aspx: * BasketController.cs: * AccountController.cs: * WorkFlowController.cs: * BlogsApiController.cs: * ChangePassword.aspx: * RemoveRoleQuery.aspx: * CreateBackup.aspx: * IContentProvider.cs: * BackOfficeController.cs: * FrontOfficeController.cs: * NpgsqlBlogProvider.cs: * NpgsqlContentProvider.cs: * RegistrationPending.aspx: * ProductCategory.aspx: * FrontOfficeApiController.cs: * ChangePasswordSuccess.aspx: * ReferenceNotFound.aspx: * BackupCreated.aspx Fixes many HTTP 500 Refactoring on the go
63 lines
1.7 KiB
C#
63 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using System.Web.Mvc.Ajax;
|
|
using System.Web.Security;
|
|
using Npgsql.Web.Blog;
|
|
using yavscModel.Blogs;
|
|
|
|
namespace Yavsc.Controllers
|
|
{
|
|
public class BlogsApiController : Controller
|
|
{
|
|
private const string adminRoleName = "Admin";
|
|
protected override void Initialize (System.Web.Routing.RequestContext requestContext)
|
|
{
|
|
base.Initialize (requestContext);
|
|
if (!Roles.RoleExists (adminRoleName)) {
|
|
Roles.CreateRole (adminRoleName);
|
|
}
|
|
}
|
|
|
|
public long Tag (long postid,string tag) {
|
|
BlogEntry e = BlogManager.GetPost (postid);
|
|
if (!Roles.IsUserInRole ("Admin")) {
|
|
string rguser = Membership.GetUser ().UserName;
|
|
if (rguser != e.UserName) {
|
|
throw new AccessViolationException (
|
|
string.Format (
|
|
"Vous n'avez pas le droit de tagger des billets du Blog de {0}",
|
|
e.UserName));
|
|
}
|
|
}
|
|
return BlogManager.Tag (postid, tag);
|
|
}
|
|
|
|
public static HttpStatusCodeResult RemovePost(string user, string title) {
|
|
if (!Roles.IsUserInRole ("Admin")) {
|
|
string rguser = Membership.GetUser ().UserName;
|
|
if (rguser != user) {
|
|
throw new AccessViolationException (
|
|
string.Format (
|
|
"Vous n'avez pas le droit de suprimer des billets du Blog de {0}",
|
|
user));
|
|
}
|
|
}
|
|
BlogEntry e = BlogManager.GetPost (user, title);
|
|
if (e == null) {
|
|
return new HttpNotFoundResult (
|
|
string.Format("Aucun post portant le titre \"{0}\" pour l'utilisateur {1}",
|
|
title, user));
|
|
}
|
|
BlogManager.RemovePost (user, title);
|
|
return new HttpStatusCodeResult (200);
|
|
}
|
|
|
|
public void RemoveTag(long tagid) {
|
|
throw new NotImplementedException ();
|
|
}
|
|
}
|
|
}
|
|
|