Skip to content

Commit 63c8da9

Browse files
committed
Curation Tool: Move hardcoded curator group to settings #2268
1 parent e741291 commit 63c8da9

File tree

6 files changed

+58
-21
lines changed

6 files changed

+58
-21
lines changed

Components/DLM/BExIS.Dlm.Entities/Curation/CurationEntry.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ public CurationEntry(string topic, CurationEntryType type, Dataset dataset, stri
6565
public virtual bool IsApproved { get; set; }
6666
public virtual DateTime LastChangeDatetime_User { get; set; }
6767
public virtual DateTime LastChangeDatetime_Curator { get; set; }
68-
public static CurationUserType GetCurationUserType(User user)
68+
69+
public static CurationUserType GetCurationUserType(User user, string curationGroupName)
6970
{
70-
if (user.Groups.Any(g => g.Name.Equals("curator", StringComparison.CurrentCultureIgnoreCase)))
71+
if (user.Groups.Any(g => g.Name.Equals(curationGroupName, StringComparison.CurrentCultureIgnoreCase)))
7172
{
7273
return CurationUserType.Curator;
7374
}

Components/DLM/BExIS.Dlm.Entities/Curation/CurationNote.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ public CurationNote(int id, CurationUserType userType, DateTime creationDate, st
2929
User = user;
3030
}
3131

32-
public CurationNote(User user, string comment)
32+
public CurationNote(User user, string comment, CurationUserType userType)
3333
{
3434
Id = 0;
35-
UserType = CurationEntry.GetCurationUserType(user);
35+
UserType = userType;
3636
CreationDate = DateTime.Now;
3737
Comment = comment;
3838
User = user;

Components/DLM/BExIS.Dlm.Services/Curation/CurationManager.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private static void FixPositions(IEnumerable<CurationEntry> entries, CurationEnt
5353
}
5454
}
5555

56-
public CurationEntry Create(string topic, CurationEntryType type, long datasetId, string name, string description, string solution, int position, string source, IEnumerable<CurationNote> notes, bool userIsDone, bool isApproved, User user)
56+
public CurationEntry Create(string topic, CurationEntryType type, long datasetId, string name, string description, string solution, int position, string source, IEnumerable<CurationNote> notes, bool userIsDone, bool isApproved, User user, bool userIsCurator)
5757
{
5858
if (string.IsNullOrEmpty(name)) throw new ArgumentNullException(nameof(name), "name is empty but is required.");
5959
if (string.IsNullOrEmpty(source)) throw new ArgumentNullException(nameof(source), "source is empty but is required.");
@@ -72,7 +72,7 @@ public CurationEntry Create(string topic, CurationEntryType type, long datasetId
7272
var _ = loadedUser.Groups.Count;
7373

7474
// set last change date time
75-
if (CurationEntry.GetCurationUserType(loadedUser) != CurationUserType.Curator)
75+
if (!userIsCurator)
7676
throw new UnauthorizedAccessException("Only curators are allowed to create curation entries.");
7777

7878
var dataset = repoDataset.Get(datasetId);
@@ -113,8 +113,7 @@ public CurationEntry Create(string topic, CurationEntryType type, long datasetId
113113
return curationEntry;
114114
}
115115
}
116-
117-
public CurationEntry Update(long id, string topic, CurationEntryType type, string name, string description, string solution, int position, string source, IEnumerable<CurationNote> notes, bool userIsDone, bool isApproved, User user)
116+
public CurationEntry Update(long id, string topic, CurationEntryType type, string name, string description, string solution, int position, string source, IEnumerable<CurationNote> notes, bool userIsDone, bool isApproved, User user, bool userIsCurator)
118117
{
119118
if (id <= 0) throw new ArgumentException("id must be greater than 0.");
120119

@@ -132,15 +131,19 @@ public CurationEntry Update(long id, string topic, CurationEntryType type, strin
132131
// Force loading of Groups collection
133132
var _ = loadedUser.Groups.Count;
134133

135-
var isCurator = CurationEntry.GetCurationUserType(loadedUser) == CurationUserType.Curator;
136-
137134
var merged = repoEntries.Get(id);
138135

139136
var currentNotes = merged.Notes.ToList();
140137

141138
var incomingIds = new HashSet<long>(notes.Select(n => n.Id));
142139
incomingIds.Remove(0);
143140
var deletedNotes = merged.Notes.Where(n => !incomingIds.Contains(n.Id)).ToList();
141+
142+
var userType = CurationUserType.User;
143+
if (userIsCurator)
144+
userType = CurationUserType.Curator;
145+
146+
144147
foreach (var note in deletedNotes)
145148
{
146149
if (loadedUser.Id != note.User.Id) continue; // do not delete notes from other users
@@ -153,7 +156,7 @@ public CurationEntry Update(long id, string topic, CurationEntryType type, strin
153156
var existingNote = currentNotes.FirstOrDefault(n => n.Id == incomingNote.Id);
154157
if (incomingNote.Id == 0 || existingNote == null)
155158
{
156-
var newNote = new CurationNote(loadedUser, incomingNote.Comment);
159+
var newNote = new CurationNote(loadedUser, incomingNote.Comment, userType);
157160
currentNotes.Add(newNote);
158161
}
159162
else
@@ -167,7 +170,7 @@ public CurationEntry Update(long id, string topic, CurationEntryType type, strin
167170

168171
var changed = false;
169172

170-
if (isCurator)
173+
if (userIsCurator)
171174
{
172175
changed = topic != merged.Topic ||
173176
type != merged.Type ||

Console/BExIS.Web.Shell/Areas/DCM/BExIS.Modules.Dcm.UI/Controllers/API/CurationEntryController.cs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private class AnonymizedCuration
3434

3535
public AnonymizedCuration(IEnumerable<CurationEntry> curationEntries, User user)
3636
{
37-
bool userIsCurator = CurationEntry.GetCurationUserType(user).Equals(CurationUserType.Curator);
37+
bool userIsCurator = CurationEntry.GetCurationUserType(user, GetCurationGroupName()).Equals(CurationUserType.Curator);
3838

3939
// requesting user gets added to the set of seen users
4040
var userSet = new HashSet<long>() { user.Id };
@@ -88,7 +88,7 @@ public AnonymizedCuration(IEnumerable<CurationEntry> curationEntries, User user)
8888

8989
// convert the user list to new userIds from 1 to n
9090
var userMap = new Dictionary<long, CurationUserModel>();
91-
for (var i = 0; i < sortedUsers.Count; i++) userMap.Add(sortedUsers[i].Id, new CurationUserModel(sortedUsers[i], i + 1));
91+
for (var i = 0; i < sortedUsers.Count; i++) userMap.Add(sortedUsers[i].Id, new CurationUserModel(sortedUsers[i], i + 1, GetCurationUserType(sortedUsers[i])));
9292

9393
// replace original userIds with the anonymized ones
9494
foreach (var curationEntry in AnonymizedCurationEntries)
@@ -139,6 +139,26 @@ private static List<CurationLabel> GetCurationLabels()
139139
return curationLabels == null ? new List<CurationLabel>() : curationLabels;
140140
}
141141

142+
private static String GetCurationGroupName()
143+
{
144+
var groupName = ModuleManager.GetModuleSettings("DDM").GetValueByKey<string>("curatorsGroupName");
145+
if (string.IsNullOrEmpty(groupName))
146+
{
147+
return "curator";
148+
}
149+
return groupName;
150+
}
151+
152+
public static CurationUserType GetCurationUserType(User user)
153+
{
154+
var curationGroupName = GetCurationGroupName();
155+
if (user.Groups.Any(g => g.Name.Equals(curationGroupName, StringComparison.CurrentCultureIgnoreCase)))
156+
{
157+
return CurationUserType.Curator;
158+
}
159+
return CurationUserType.User;
160+
}
161+
142162
private static IEnumerable<CurationTemplateModel> GetGreetingTemplates()
143163
{
144164
// this should be replaced by a configuration or derived from other source in the future
@@ -216,7 +236,7 @@ public async Task<HttpResponseMessage> Get(long datasetid)
216236
var greetingTemplates = GetGreetingTemplates();
217237
var taskListTemplates = GetTaskListTemplates();
218238

219-
bool userIsCurator = CurationEntry.GetCurationUserType(userWithGroups).Equals(CurationUserType.Curator);
239+
bool userIsCurator = CurationEntry.GetCurationUserType(userWithGroups, GetCurationGroupName()).Equals(CurationUserType.Curator);
220240

221241
curationModel = new CurationModel(
222242
datasetid,
@@ -337,6 +357,7 @@ public async Task<HttpResponseMessage> Put(CurationEntryModel curationEntryModel
337357
// check if user has rights to access the dataset
338358
//if (!(userRights(user.Id, c.Dataset.Id) > 0))
339359
// return Request.CreateErrorResponse(HttpStatusCode.PreconditionFailed, "User has no rights to access the dataset");
360+
bool userIsCurator = CurationEntry.GetCurationUserType(userWithGroups, GetCurationGroupName()).Equals(CurationUserType.Curator);
340361

341362
var newCurationEntry = curationManager.Update(
342363
curationEntryModel.Id,
@@ -350,7 +371,8 @@ public async Task<HttpResponseMessage> Put(CurationEntryModel curationEntryModel
350371
notes,
351372
curationEntryModel.UserIsDone,
352373
curationEntryModel.IsApproved,
353-
userWithGroups
374+
userWithGroups,
375+
userIsCurator
354376
);
355377

356378
var response = AnonymizeCurationEntryModel(curationEntryModel, newCurationEntry, userWithGroups);
@@ -385,15 +407,18 @@ public async Task<HttpResponseMessage> Post(CurationEntryModel curationEntryMode
385407
.Where(u => u.Id == user.Id)
386408
.Fetch(u => u.Groups)
387409
.SingleOrDefault();
410+
411+
var userIsCurator = CurationEntry.GetCurationUserType(userWithGroups, GetCurationGroupName()).Equals(CurationUserType.Curator);
388412

389-
if (!CurationEntry.GetCurationUserType(userWithGroups).Equals(CurationUserType.Curator))
413+
if (!CurationEntry.GetCurationUserType(userWithGroups, GetCurationGroupName()).Equals(CurationUserType.Curator))
390414
return Request.CreateErrorResponse(HttpStatusCode.PreconditionFailed, "User not permitted to create curation entries");
391415

392416
List<CurationNote> notes;
393417
if (curationEntryModel.Notes == null || !curationEntryModel.Notes.Any())
394418
notes = new List<CurationNote>();
395419
else
396-
notes = curationEntryModel.Notes.Select(n => new CurationNote(userWithGroups, n.Comment)).ToList(); // all notes will be created for the current user
420+
421+
notes = curationEntryModel.Notes.Select(n => new CurationNote(userWithGroups, n.Comment, GetCurationUserType(userWithGroups))).ToList(); // all notes will be created for the current user
397422

398423
if (curationEntryModel.Type == CurationEntryType.StatusEntryItem)
399424
{
@@ -419,7 +444,8 @@ public async Task<HttpResponseMessage> Post(CurationEntryModel curationEntryMode
419444
notes,
420445
curationEntryModel.UserIsDone,
421446
curationEntryModel.IsApproved,
422-
userWithGroups
447+
userWithGroups,
448+
userIsCurator
423449
);
424450

425451
var response = AnonymizeCurationEntryModel(curationEntryModel, newCurationEntry, userWithGroups);

Console/BExIS.Web.Shell/Areas/DCM/BExIS.Modules.Dcm.UI/Models/Curation/Curation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ public CurationUserModel(long id, string displayName, CurationUserType curationU
123123
CurationUserType = curationUserType;
124124
}
125125

126-
public CurationUserModel(User user, long id)
126+
public CurationUserModel(User user, long id, CurationUserType curationUserType)
127127
{
128128
Id = id;
129129
DisplayName = user.DisplayName;
130-
CurationUserType = CurationEntry.GetCurationUserType(user);
130+
CurationUserType = curationUserType;
131131
}
132132
}
133133

Console/BExIS.Web.Shell/Areas/DDM/BExIS.Modules.Ddm.UI/Ddm.Settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@
7272
"downloadCitationFormats": [ "Text", "APA", "RIS", "BibTex" ]
7373
}
7474
},
75+
{
76+
"key": "curatorsGroupName",
77+
"title": "Group name for curators",
78+
"value": "curator",
79+
"type": "String",
80+
"description": "Group name all curators assigned to. This is needed for the curation tool to know who is curator."
81+
},
7582
{
7683
"key": "curation",
7784
"title": "Configuration Settings for Curation",

0 commit comments

Comments
 (0)