User Flag Expressions
Adds the ability to have expressions evaluated when flags are added and removed.
This commit is contained in:
@@ -75,7 +75,9 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
[DiscoAuthorizeAny(Claims.User.Actions.AddFlags)]
|
||||
public virtual ActionResult AddUser(int id, string UserId, string Comments)
|
||||
{
|
||||
var userFlag = UserFlagService.GetUserFlag(id);
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
|
||||
var userFlag = Database.UserFlags.Find(id);
|
||||
if (userFlag == null)
|
||||
throw new ArgumentException("Invalid User Flag Id", "id");
|
||||
|
||||
@@ -86,8 +88,9 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
if (!user.CanAddUserFlag(userFlag))
|
||||
throw new InvalidOperationException("Adding user flag is denied");
|
||||
|
||||
var userFlagAssignment = user.OnAddUserFlag(Database, userFlag, CurrentUser, Comments);
|
||||
Database.SaveChanges();
|
||||
var addingUser = Database.Users.Find(CurrentUser.UserId);
|
||||
|
||||
var userFlagAssignment = user.OnAddUserFlag(Database, userFlag, addingUser, Comments);
|
||||
|
||||
return Redirect(string.Format("{0}#UserDetailTab-Flags", Url.Action(MVC.User.Show(user.UserId))));
|
||||
}
|
||||
@@ -95,6 +98,8 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
[DiscoAuthorizeAny(Claims.User.Actions.RemoveFlags)]
|
||||
public virtual ActionResult RemoveUser(int id)
|
||||
{
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
|
||||
var userFlagAssignment = Database.UserFlagAssignments.FirstOrDefault(a => a.Id == id);
|
||||
if (userFlagAssignment == null)
|
||||
throw new ArgumentException("Invalid User Flag Assignment Id", "id");
|
||||
@@ -102,7 +107,9 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
if (!userFlagAssignment.CanRemove())
|
||||
throw new InvalidOperationException("Removing user flag assignment is denied");
|
||||
|
||||
userFlagAssignment.OnRemove(CurrentUser);
|
||||
var removingUser = Database.Users.Find(CurrentUser.UserId);
|
||||
|
||||
userFlagAssignment.OnRemove(Database, removingUser);
|
||||
Database.SaveChanges();
|
||||
|
||||
return Redirect(string.Format("{0}#UserDetailTab-Flags", Url.Action(MVC.User.Show(userFlagAssignment.UserId))));
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Services;
|
||||
using Disco.Services.Authorization;
|
||||
using Disco.Services.Interop.ActiveDirectory;
|
||||
using Disco.Services.Tasks;
|
||||
@@ -16,6 +17,8 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
const string pDescription = "description";
|
||||
const string pIcon = "icon";
|
||||
const string pIconColour = "iconcolour";
|
||||
const string pOnAssignmentExpression = "onassignmentexpression";
|
||||
const string pOnUnassignmentExpression = "onunassignmentexpression";
|
||||
|
||||
[DiscoAuthorize(Claims.Config.UserFlag.Configure)]
|
||||
public virtual ActionResult Update(int id, string key, string value = null, Nullable<bool> redirect = null)
|
||||
@@ -45,6 +48,12 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
case pIconColour:
|
||||
UpdateIconColour(flag, value);
|
||||
break;
|
||||
case pOnAssignmentExpression:
|
||||
UpdateOnAssignmentExpression(flag, value);
|
||||
break;
|
||||
case pOnUnassignmentExpression:
|
||||
UpdateOnUnassignmentExpression(flag, value);
|
||||
break;
|
||||
default:
|
||||
throw new Exception("Invalid Update Key");
|
||||
}
|
||||
@@ -123,6 +132,16 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
}
|
||||
}
|
||||
[DiscoAuthorize(Claims.Config.UserFlag.Configure)]
|
||||
public virtual ActionResult UpdateOnAssignmentExpression(int id, string OnAssignmentExpression = null, bool redirect = false)
|
||||
{
|
||||
return Update(id, pOnAssignmentExpression, OnAssignmentExpression, redirect);
|
||||
}
|
||||
[DiscoAuthorize(Claims.Config.UserFlag.Configure)]
|
||||
public virtual ActionResult UpdateOnUnassignmentExpression(int id, string OnUnassignmentExpression = null, bool redirect = false)
|
||||
{
|
||||
return Update(id, pOnUnassignmentExpression, OnUnassignmentExpression, redirect);
|
||||
}
|
||||
[DiscoAuthorize(Claims.Config.UserFlag.Configure)]
|
||||
public virtual ActionResult UpdateAssignedUsersLinkedGroup(int id, string GroupId = null, DateTime? FilterBeginDate = null, bool redirect = false)
|
||||
{
|
||||
try
|
||||
@@ -247,6 +266,38 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateOnAssignmentExpression(UserFlag UserFlag, string OnAssignmentExpression)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(OnAssignmentExpression))
|
||||
{
|
||||
UserFlag.OnAssignmentExpression = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
UserFlag.OnAssignmentExpression = OnAssignmentExpression.Trim();
|
||||
}
|
||||
// Invalidate Cache
|
||||
UserFlag.OnAssignmentExpressionInvalidateCache();
|
||||
|
||||
UserFlagService.Update(Database, UserFlag);
|
||||
}
|
||||
|
||||
private void UpdateOnUnassignmentExpression(UserFlag UserFlag, string OnUnassignmentExpression)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(OnUnassignmentExpression))
|
||||
{
|
||||
UserFlag.OnUnassignmentExpression = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
UserFlag.OnUnassignmentExpression = OnUnassignmentExpression.Trim();
|
||||
}
|
||||
// Invalidate Cache
|
||||
UserFlag.OnUnassignmentExpressionInvalidateCache();
|
||||
|
||||
UserFlagService.Update(Database, UserFlag);
|
||||
}
|
||||
|
||||
private ScheduledTaskStatus UpdateAssignedUsersLinkedGroup(UserFlag UserFlag, string AssignedUsersLinkedGroup, DateTime? FilterBeginDate)
|
||||
{
|
||||
var configJson = ADManagedGroup.ValidConfigurationToJson(UserFlagUsersManagedGroup.GetKey(UserFlag), AssignedUsersLinkedGroup, FilterBeginDate);
|
||||
|
||||
@@ -14,7 +14,9 @@
|
||||
|
||||
var hideAdvanced =
|
||||
Model.UserFlag.UserDevicesLinkedGroup == null &&
|
||||
Model.UserFlag.UsersLinkedGroup == null;
|
||||
Model.UserFlag.UsersLinkedGroup == null &&
|
||||
Model.UserFlag.OnAssignmentExpression == null &&
|
||||
Model.UserFlag.OnUnassignmentExpression == null;
|
||||
|
||||
Html.BundleDeferred("~/ClientScripts/Modules/Disco-PropertyChangeHelpers");
|
||||
}
|
||||
@@ -222,6 +224,147 @@
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
<tr class="Config_HideAdvanced_Item">
|
||||
<th>
|
||||
On Assignment<br />Expression:
|
||||
</th>
|
||||
<td>
|
||||
@if (canConfig)
|
||||
{
|
||||
@Html.EditorFor(model => model.UserFlag.OnAssignmentExpression)
|
||||
@AjaxHelpers.AjaxRemove()
|
||||
@AjaxHelpers.AjaxSave()
|
||||
@AjaxHelpers.AjaxLoader()
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
var field = $('#UserFlag_OnAssignmentExpression');
|
||||
var fieldRemove = field.next('.ajaxRemove');
|
||||
var fieldOriginalWidth, fieldOriginalHeight;
|
||||
|
||||
document.DiscoFunctions.PropertyChangeHelper(
|
||||
field,
|
||||
'None',
|
||||
'@Url.Action(MVC.API.UserFlag.UpdateOnAssignmentExpression(Model.UserFlag.Id))',
|
||||
'OnAssignmentExpression'
|
||||
);
|
||||
|
||||
field.focus(function () {
|
||||
fieldOriginalWidth = field.width();
|
||||
fieldOriginalHeight = field.height();
|
||||
field.css('overflow', 'visible').animate({ width: field.parent().width() - 42, height: 75 }, 200);
|
||||
}).blur(function () {
|
||||
field.css('overflow', 'hidden').animate({ width: fieldOriginalWidth, height: fieldOriginalHeight }, 200);
|
||||
}).change(function () {
|
||||
if (!!field.val()) {
|
||||
fieldRemove.show();
|
||||
} else {
|
||||
fieldRemove.hide();
|
||||
}
|
||||
}).attr('placeholder', 'None').attr('spellcheck', 'false');
|
||||
|
||||
fieldRemove.click(function () {
|
||||
field.val('').change();
|
||||
});
|
||||
|
||||
if (!!field.val()) {
|
||||
fieldRemove.show();
|
||||
} else {
|
||||
fieldRemove.hide();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Model.UserFlag.OnAssignmentExpression))
|
||||
{
|
||||
<span class="smallMessage"><None Specified></span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="code">
|
||||
@Model.UserFlag.OnAssignmentExpression
|
||||
</div>
|
||||
}
|
||||
}
|
||||
<div class="info-box">
|
||||
<p class="fa-p">
|
||||
<i class="fa fa-fw fa-info-circle"></i>This expression will be evaluated whenever the user flag is assigned to a user. The output of the expression will be shown with the flag assignment.
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
<tr class="Config_HideAdvanced_Item">
|
||||
<th>
|
||||
On Unassignment<br />Expression:
|
||||
</th>
|
||||
<td>
|
||||
@if (canConfig)
|
||||
{
|
||||
@Html.EditorFor(model => model.UserFlag.OnUnassignmentExpression)
|
||||
@AjaxHelpers.AjaxRemove()
|
||||
@AjaxHelpers.AjaxSave()
|
||||
@AjaxHelpers.AjaxLoader()
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
var field = $('#UserFlag_OnUnassignmentExpression');
|
||||
var fieldRemove = field.next('.ajaxRemove');
|
||||
var fieldOriginalWidth, fieldOriginalHeight;
|
||||
|
||||
document.DiscoFunctions.PropertyChangeHelper(
|
||||
field,
|
||||
'None',
|
||||
'@Url.Action(MVC.API.UserFlag.UpdateOnUnassignmentExpression(Model.UserFlag.Id))',
|
||||
'OnUnassignmentExpression'
|
||||
);
|
||||
|
||||
field.focus(function () {
|
||||
fieldOriginalWidth = field.width();
|
||||
fieldOriginalHeight = field.height();
|
||||
field.css('overflow', 'visible').animate({ width: field.parent().width() - 42, height: 75 }, 200);
|
||||
}).blur(function () {
|
||||
field.css('overflow', 'hidden').animate({ width: fieldOriginalWidth, height: fieldOriginalHeight }, 200);
|
||||
}).change(function () {
|
||||
if (!!field.val()) {
|
||||
fieldRemove.show();
|
||||
} else {
|
||||
fieldRemove.hide();
|
||||
}
|
||||
}).attr('placeholder', 'None').attr('spellcheck', 'false');
|
||||
|
||||
fieldRemove.click(function () {
|
||||
field.val('').change();
|
||||
});
|
||||
|
||||
if (!!field.val()) {
|
||||
fieldRemove.show();
|
||||
} else {
|
||||
fieldRemove.hide();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Model.UserFlag.OnUnassignmentExpression))
|
||||
{
|
||||
<span class="smallMessage"><None Specified></span>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="code">
|
||||
@Model.UserFlag.OnUnassignmentExpression
|
||||
</div>
|
||||
}
|
||||
}
|
||||
<div class="info-box">
|
||||
<p class="fa-p">
|
||||
<i class="fa fa-fw fa-info-circle"></i>This expression will be evaluated whenever the user flag is removed from a user. The output of the expression will be shown with the flag assignment.
|
||||
</p>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr class="Config_HideAdvanced_Item">
|
||||
<th>
|
||||
Linked Groups:
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user