Skip to content

Commit

Permalink
TRIF-1200: Author not being set when IG has no permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcilvenna committed Apr 26, 2017
1 parent edc6a17 commit 2e667a9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
29 changes: 19 additions & 10 deletions Trifolia.Web/Controllers/API/TemplateController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SearchUserModel> 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();
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Trifolia.Web/Scripts/TemplateEdit/templateEditModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2e667a9

Please sign in to comment.