diff --git a/Trifolia.Web/Controllers/API/TemplateController.cs b/Trifolia.Web/Controllers/API/TemplateController.cs index ed68833f..d93fc0c0 100644 --- a/Trifolia.Web/Controllers/API/TemplateController.cs +++ b/Trifolia.Web/Controllers/API/TemplateController.cs @@ -330,21 +330,30 @@ join p in viewableTemplates on t.Id equals p.TemplateId return model; } - [HttpGet, Route("api/Template/Permissions/{templateId}")] + [HttpGet, Route("api/Template/{templateId}/Permissions")] public List GetTemplatePermissionsName(int templateId) { - var userIds = (from tp in this.tdb.ViewTemplatePermissions - where tp.TemplateId == templateId && tp.Permission == "Edit" - select tp.UserId).ToList(); - - var users = (from user in this.tdb.Users - join u in userIds on user.Id equals u - select user) - .ToList(); + Template template = this.tdb.Templates.Single(y => y.Id == templateId); + var users = (from tp in this.tdb.ViewTemplatePermissions + join u in this.tdb.Users on tp.UserId equals u.Id + where tp.TemplateId == templateId && tp.Permission == "Edit" + select u).ToList(); var usersList = users.Select(y => new SearchUserModel(y)).ToList(); - return usersList; + // Add the current user to the list if they are a data admin. + // Data admins don't require explicit permissions. + if (CheckPoint.Instance.IsDataAdmin) + { + User currentUser = CheckPoint.Instance.GetUser(this.tdb); + usersList.Add(new SearchUserModel(currentUser)); + } + + // Add the current author of the template to the list if they are not already there + if (!users.Any(y => y.Id == template.AuthorId)) + usersList.Add(new SearchUserModel(template.Author)); + + return usersList.OrderBy(y => y.Name).ToList(); } /// diff --git a/Trifolia.Web/Scripts/TemplateEdit/templateEditModels.js b/Trifolia.Web/Scripts/TemplateEdit/templateEditModels.js index 2a7598b1..9d3e8ae8 100644 --- a/Trifolia.Web/Scripts/TemplateEdit/templateEditModels.js +++ b/Trifolia.Web/Scripts/TemplateEdit/templateEditModels.js @@ -968,7 +968,7 @@ var TemplateModel = function (data, viewModel) { var users = {}; $.ajax({ - url: "/api/Template/Permissions/" + tId, + url: "/api/Template/" + tId + "/Permissions", async: false, success: function (results) { userInfo = results;