-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseFileManagementController.cs
More file actions
158 lines (127 loc) · 5.61 KB
/
Copy pathBaseFileManagementController.cs
File metadata and controls
158 lines (127 loc) · 5.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
using BExIS.Modules.FMT.UI.Helper;
using BExIS.Modules.FMT.UI.Models;
using BExIS.Security.Entities.Objects;
using BExIS.Security.Services.Authorization;
using BExIS.Security.Services.Objects;
using BExIS.Security.Services.Subjects;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Vaiona.IoC;
using Vaiona.Utils.Cfg;
using Vaiona.Web.Extensions;
using Vaiona.Web.Mvc.Models;
using Vaiona.Web.Mvc.Modularity;
namespace BExIS.Modules.Fmt.UI.Controllers
{
public class BaseFileManagementController : Controller
{
private readonly UserManager _userManager;
public BaseFileManagementController(UserManager userManager)
{
_userManager = userManager;
}
public BaseFileManagementController()
{
_userManager = IoCFactory.Container.Resolve<UserManager>();
}
public ActionResult Show(string viewName, string rootMenu, string viewTitle)
{
ViewBag.Title = PresentationModel.GetViewTitleForTenant(viewTitle, this.Session.GetTenant());
bool hasAdminRights = false;
string userName = HttpContext.User.Identity.Name;
if (!String.IsNullOrEmpty(userName))
{
using (FeaturePermissionManager featurePermissionManager = new FeaturePermissionManager())
using (FeatureManager featureManager = new FeatureManager())
{
var userTask = _userManager.FindByNameAsync(userName);
userTask.Wait();
var user = userTask.Result;
var feature = featureManager.FindByName(viewName + "Admin");
hasAdminRights = featurePermissionManager.HasAccessAsync(user.Id, feature.Id).Result;
}
}
if (String.IsNullOrEmpty(rootMenu))
ModelState.AddModelError("Error", "Please enter a menu root to the url!");
if (String.IsNullOrEmpty(viewName))
ModelState.AddModelError("Error", "Please enter a view name to the url!");
MenuHelper menuHelper = new MenuHelper();
List<FMTMenuItem> menus = null;
bool hasUserRights = false;
if (rootMenu != "")
hasUserRights = menuHelper.HasUserAccessRights(rootMenu, userName);
if (!hasUserRights)
ModelState.AddModelError("Error", "No access rights for this menu and this page!");
else
menus = menuHelper.GetMenu(rootMenu, userName);
//if (string.IsNullOrEmpty(rootMenu))
ViewBag.UseLayout = true;
ViewData["AdminRights"] = hasAdminRights;
return View(viewName, menus);
}
public ActionResult GetFileLists(string menuItemPath, string contollerName)
{
//string menuItem = new DirectoryInfo(menuItemPath).Name;
string userName = GetUsernameOrDefault();
bool hasDeleteRights = false;
if (!String.IsNullOrEmpty(userName))
{
//check user permissions for delete
using (var featurePermissionManager = new FeaturePermissionManager())
using (var featureManager = new FeatureManager())
{
var userTask = _userManager.FindByNameAsync(userName);
userTask.Wait();
var user = userTask.Result;
List<Feature> features = featureManager.FeatureRepository.Get().ToList();
Feature feature = features.FirstOrDefault(f => f.Name.Equals(contollerName + "Admin"));
if (feature != null)
{
if (featurePermissionManager.HasAccessAsync(user.Id, feature.Id).Result)
{
hasDeleteRights = true;
}
}
}
}
var fileModelList = FileModel.GetFileModelList(menuItemPath, hasDeleteRights);
fileModelList.ForEach(a => a.controllerName = contollerName);
return PartialView("~/Areas/FMT/Views/Shared/_fileList.cshtml", fileModelList);
}
public ActionResult DownloadFile(string path, string mimeType)
{
string title = path.Split('\\').Last();
string message = string.Format("file was downloaded");
string userName = GetUsernameOrDefault();
Vaiona.Logging.LoggerFactory.LogCustom(message);
string message_mail = $"Dataset <b>\"{title}\"</b> with id was downloaded";
if (!string.IsNullOrEmpty(userName))
{
message_mail += $" by <b>{userName}</b>";
}
message_mail = message_mail + ".";
//var es = new Security.Services.Utilities.EmailService();
// es.Send(MessageHelper.GetDownloadDatasetHeader(),message_mail, ConfigurationManager.AppSettings["SystemEmail"]);
string folderpath = "";
var settings = ModuleManager.GetModuleSettings("fmt");
folderpath = settings.GetValueByKey("SourcePathToFiles").ToString();
if (String.IsNullOrEmpty(path))
folderpath = AppConfiguration.DataPath;
return File(Path.Combine(folderpath, path), mimeType, title);
}
public string GetUsernameOrDefault()
{
string username = null;
try
{
username = HttpContext.User.Identity.Name;
}
catch { }
return username;
}
}
}