This commit is contained in:
Paul Schneider
2014-10-12 15:22:45 +02:00
parent 83ac08cfd4
commit 1606fd0871
17 changed files with 136 additions and 90 deletions

View File

@ -8,6 +8,7 @@ using System.Web.Security;
using Yavsc.Model.RolesAndMembers;
using Yavsc.Model.Admin;
using Yavsc.Admin;
using System.IO;
namespace Yavsc.Controllers
@ -27,6 +28,7 @@ namespace Yavsc.Controllers
[Authorize(Roles="Admin")]
public ActionResult Backups(DataAccess model)
{
return View (model);
}
@ -37,6 +39,7 @@ namespace Yavsc.Controllers
if (ModelState.IsValid) {
if (string.IsNullOrEmpty (datac.Password))
ModelState.AddModelError ("Password", "Invalid passord");
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
DataManager ex = new DataManager (datac);
Export e = ex.CreateBackup ();
if (e.ExitCode > 0)
@ -65,14 +68,30 @@ namespace Yavsc.Controllers
{
ViewData ["BackupName"] = backupName;
if (ModelState.IsValid) {
// TODO BETTER
datac.BackupPrefix = Server.MapPath (datac.BackupPrefix);
DataManager mgr = new DataManager (datac);
ViewData ["BackupName"] = backupName;
ViewData ["DataOnly"] = dataOnly;
TaskOutput t = mgr.Restore (backupName,dataOnly);
TaskOutput t = mgr.Restore (
Path.Combine(new FileInfo(datac.BackupPrefix).DirectoryName,
backupName),dataOnly);
return View ("Restored", t);
}
BuildBackupList (datac);
return View (datac);
}
private void BuildBackupList(DataAccess datac)
{
// build ViewData ["Backups"];
string bckd=Server.MapPath (datac.BackupPrefix);
DirectoryInfo di = new DirectoryInfo (new FileInfo(bckd).DirectoryName);
List<string> bks = new List<string> ();
foreach (FileInfo ti in di.GetFiles("*.tar"))
bks.Add (ti.Name);
ViewData ["Backups"] = bks.ToArray ();
}
[Authorize(Roles="Admin")]
public ActionResult RemoveFromRole(string username, string rolename, string returnUrl)

View File

@ -20,19 +20,37 @@ namespace Yavsc.Controllers
/// </summary>
public class FrontOfficeController : Controller
{
[HttpGet]
[HttpPost]
public ActionResult Estimate(Estimate e)
[Authorize]
public ActionResult Estimate(Estimate model,string submit)
{
if (ModelState.IsValid) {
if (e.Id > 0) {
Estimate f = WorkFlowManager.GetEstimate (e.Id);
if (e.Owner != f.Owner)
string username = HttpContext.User.Identity.Name;
if (model.Id > 0) {
Estimate f = WorkFlowManager.GetEstimate (model.Id);
if (f == null) {
ModelState.AddModelError ("Id", "Wrong Id");
return View (model);
}
if (username != f.Owner)
if (!Roles.IsUserInRole ("FrontOffice"))
throw new UnauthorizedAccessException ("You're not allowed to modify this estimate");
throw new UnauthorizedAccessException ("You're not allowed to view/modify this estimate");
if (submit == "Update") {
if (model != f) {
WorkFlowManager.SetTitle (model.Id, model.Title);
}
} else if (submit == null) {
model = f;
}
} else if (model.Id == 0 && submit=="Create") {
// Create the estimate
model.Id=WorkFlowManager.CreateEstimate (username,
model.Title);
model.Owner = username;
}
}
return View (e);
return View(model);
}
[AcceptVerbs("GET")]

View File

@ -52,6 +52,7 @@ namespace Yavsc.ApiControllers
{
WorkFlowManager.DropEstimate (estid);
}
[HttpGet]
[Authorize]
public object Index()
@ -60,48 +61,12 @@ namespace Yavsc.ApiControllers
string username = Membership.GetUser ().UserName;
return new { test=string.Format("Hello {0}!",username) };
}
[HttpGet]
[Authorize]
public long Write (long estid, string desc, decimal ucost, int count, long productid=0) {
// TODO ensure estid owner matches the current one
return WorkFlowManager.Write(estid, desc, ucost, count, productid);
}
/*
public object Details(int id)
{
throw new NotImplementedException ();
}
public object Create()
{
throw new NotImplementedException ();
}
public object Edit(int id)
{
throw new NotImplementedException ();
}
public object Delete(int id)
{
throw new NotImplementedException ();
}
IContentProvider contentProvider = null;
IContentProvider ContentProvider {
get {
if (contentProvider == null )
contentProvider = WFManager.GetContentProviderFWC ();
return contentProvider;
}
}
*/
}
}