Skip to content

Commit

Permalink
#1575 template is enhanced, ui and backend functions are set
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBlaa committed Feb 28, 2024
1 parent 89af403 commit a724b39
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 13 deletions.
30 changes: 26 additions & 4 deletions Components/DLM/BExIS.Dlm.Entities/Data/EntityTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,16 @@ public virtual List<long> NotificationGroups
/// when a email is sended to the owner or admin send also to this groups
/// </summary>
public virtual string JsonPermissionGroups { get; set; }
public virtual List<long> PermissionGroups
public virtual PermissionsType PermissionGroups
{
get
{
return JsonConvert.DeserializeObject<List<long>>(JsonPermissionGroups);
try{
return JsonConvert.DeserializeObject<PermissionsType>(JsonPermissionGroups);
}
catch {
return new PermissionsType();
}
}
set
{
Expand All @@ -151,7 +156,7 @@ public EntityTemplate()
DisabledHooks = new List<string>();
DatastructureList = new List<long>();
MetadataFields = new List<int>();
PermissionGroups = new List<long>();
PermissionGroups = new PermissionsType();
NotificationGroups = new List<long>();


Expand All @@ -173,7 +178,7 @@ public EntityTemplate(string name, string description, Entity entityType, Metada
DisabledHooks = new List<string>();
DatastructureList = new List<long>();
MetadataFields = new List<int>();
PermissionGroups = new List<long>();
PermissionGroups = new PermissionsType();
NotificationGroups = new List<long>();

JsonAllowedFileTypes = "";
Expand All @@ -185,4 +190,21 @@ public EntityTemplate(string name, string description, Entity entityType, Metada
}

}

public class PermissionsType
{
public List<long> Full { get; set; }
public List<long> ViewEditGrant { get; set; }
public List<long> ViewEdit { get; set; }
public List<long> View { get; set; }

public PermissionsType()
{
Full = new List<long>();
ViewEditGrant = new List<long>();
View = new List<long>();
ViewEdit = new List<long>();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ export interface EntityTemplateModel {
allowedFileTypes: string[];
disabledHooks: string[];
notificationGroups: number[];
permissionGroups: number[];
permissionGroups: permissionsType;
linkedSubjects: ListItem[];
}

export interface permissionsType {
full: number[];
viewEditGrant: number[];
viewEdit: number[];
view: number[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,62 @@
</div>

<h3 class="h3">Administration</h3>
<p class="p">Set permissions per default to the following groups</p>
<div class="py-5 w-full grid grid-cols-1 md:grid-cols-2 gap-4">
<EntryContainer>
<MultiSelect
id="permissions"
title="Set full permissions per default to the following groups"
id="permissionsFull"
title="Full"
source={groups}
bind:target={entityTemplate.permissionGroups}
bind:target={entityTemplate.permissionGroups.full}
itemId="key"
itemLabel="value"
complexSource={true}
help={true}
/>
</EntryContainer>

<EntryContainer>
<MultiSelect
id="permissionsViewEditGrant"
title="View, Edit and Grant"
source={groups}
bind:target={entityTemplate.permissionGroups.viewEditGrant}
itemId="key"
itemLabel="value"
complexSource={true}
help={true}
/>
</EntryContainer>

<EntryContainer>
<MultiSelect
id="permissionsViewEdit"
title="View and Edit"
source={groups}
bind:target={entityTemplate.permissionGroups.viewEdit}
itemId="key"
itemLabel="value"
complexSource={true}
help={true}
/>
</EntryContainer>

<EntryContainer>
<MultiSelect
id="permissionsView"
title="View"
source={groups}
bind:target={entityTemplate.permissionGroups.view}
itemId="key"
itemLabel="value"
complexSource={true}
help={true}
/>
</EntryContainer>
</div>
<h3 class="h3">Notifications</h3>
<div class="py-5 w-full grid grid-cols-1 md:grid-cols-2 gap-4">
<EntryContainer>
<MultiSelect
id="notification"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,38 @@ public JsonResult Create(CreateModel data)

if (entityTemplate.PermissionGroups != null)
{
foreach (var groupId in entityTemplate.PermissionGroups)
// full
foreach (var groupId in entityTemplate.PermissionGroups.Full)
{
var group = gm.Groups.Where(g => g.Id.Equals(groupId)).FirstOrDefault();
entityPermissionManager.Create<Group>(group.Name, entityTemplate.EntityType.Name, typeof(Dataset), ds.Id, Enum.GetValues(typeof(RightType)).Cast<RightType>().ToList());
}


// ViewEditGrant
foreach (var groupId in entityTemplate.PermissionGroups.ViewEditGrant)
{
var group = gm.Groups.Where(g => g.Id.Equals(groupId)).FirstOrDefault();
var l = new List<RightType>() { RightType.Read, RightType.Write, RightType.Grant };

entityPermissionManager.Create<Group>(group.Name, entityTemplate.EntityType.Name, typeof(Dataset), ds.Id, l);
}

// ViewEdit
foreach (var groupId in entityTemplate.PermissionGroups.ViewEdit)
{
var group = gm.Groups.Where(g => g.Id.Equals(groupId)).FirstOrDefault();
var l = new List<RightType>() { RightType.Read, RightType.Write };
entityPermissionManager.Create<Group>(group.Name, entityTemplate.EntityType.Name, typeof(Dataset), ds.Id,l);
}

// View
foreach (var groupId in entityTemplate.PermissionGroups.View)
{
var group = gm.Groups.Where(g => g.Id.Equals(groupId)).FirstOrDefault();
var l = new List<RightType>() { RightType.Read};
entityPermissionManager.Create<Group>(group.Name, entityTemplate.EntityType.Name, typeof(Dataset), ds.Id,l);
}
}

if (GetUsernameOrDefault() != "DEFAULT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static EntityTemplateModel ConvertTo(EntityTemplate entityTemplate)
model.DisabledHooks = entityTemplate.DisabledHooks != null ? entityTemplate.DisabledHooks : new List<string>(); ;
model.DatastructureList = entityTemplate.DatastructureList != null ? entityTemplate.DatastructureList : new List<long>();
model.AllowedFileTypes = entityTemplate.AllowedFileTypes != null ? entityTemplate.AllowedFileTypes : new List<string>();
model.PermissionGroups = entityTemplate.PermissionGroups != null ? entityTemplate.PermissionGroups : new List<long>();
model.PermissionGroups = entityTemplate.PermissionGroups != null ? entityTemplate.PermissionGroups : new PermissionsType();
model.NotificationGroups = entityTemplate.NotificationGroups != null ? entityTemplate.NotificationGroups : new List<long>();
model.MetadataFields = entityTemplate.MetadataFields != null ? entityTemplate.MetadataFields : new List<int>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BExIS.UI.Models;
using BExIS.Dlm.Entities.Data;
using BExIS.UI.Models;
using System.Collections.Generic;

namespace BExIS.Modules.Dcm.UI.Models.EntityTemplate
Expand Down Expand Up @@ -71,7 +72,7 @@ public class EntityTemplateModel
/// add this groups to the permissions
/// when a email is sended to the owner or admin send also to this groups
/// </summary>
public virtual List<long> PermissionGroups { get; set; }
public virtual PermissionsType PermissionGroups { get; set; }

/// <summary>
/// list of all suject that are created withthis template
Expand All @@ -89,7 +90,7 @@ public EntityTemplateModel()
DisabledHooks = new List<string>();
DatastructureList = new List<long>();
MetadataFields = new List<int>();
PermissionGroups = new List<long>();
PermissionGroups = new PermissionsType();
NotificationGroups = new List<long>();
MetadataInvalidSaveMode = false;
HasDatastructure = false;
Expand Down

0 comments on commit a724b39

Please sign in to comment.