Skip to content

Commit

Permalink
Merge pull request #180 from TAMULib/product-sprint6-174
Browse files Browse the repository at this point in the history
Issue 174: 401 when viewing service and a feature proposal for that service is edited in another browser
  • Loading branch information
kaladay committed Sep 14, 2020
2 parents 13dd8a9 + bb6d34a commit 74aa1b7
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions app/repo/ideaRepo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
app.repo("IdeaRepo", function IdeaRepo(WsApi, Idea, ServiceRepo, TableFactory) {
app.repo("IdeaRepo", function IdeaRepo(WsApi, Idea, ServiceRepo, TableFactory, UserService) {

var ideaRepo = this;

Expand Down Expand Up @@ -59,23 +59,46 @@ app.repo("IdeaRepo", function IdeaRepo(WsApi, Idea, ServiceRepo, TableFactory) {
}
};

WsApi.listen(ideaRepo.mapping.createListen).then(null, null, function (response) {
ServiceRepo.addIdea(new Idea(angular.fromJson(response.body).payload.Idea));
table.getTableParams().reload();
});
var canAccess = function () {
var user = UserService.getCurrentUser();
var access = false;

WsApi.listen(ideaRepo.mapping.updateListen).then(null, null, function (response) {
var idea = new Idea(angular.fromJson(response.body).payload.Idea);
ServiceRepo.updateIdea(idea);
updateIdea(idea);
table.getTableParams().reload();
});
if (user.role === undefined || user.role === null || user.anonymous) {
access = false;
}
else if (user.role === 'ROLE_ADMIN') {
access = true;
} else if (user.role === 'ROLE_SERVICE_ADMIN') {
access = true;
} else if (user.role === 'ROLE_SERVICE_MANAGER') {
access = true;
}

return access;
};

UserService.userReady().then(function () {
if (canAccess()) {

WsApi.listen(ideaRepo.mapping.createListen).then(null, null, function (response) {
ServiceRepo.addIdea(new Idea(angular.fromJson(response.body).payload.Idea));
table.getTableParams().reload();
});

WsApi.listen(ideaRepo.mapping.deleteListen).then(null, null, function (response) {
ServiceRepo.removeIdeaById(angular.fromJson(response.body).payload.Long);
table.getTableParams().reload();
WsApi.listen(ideaRepo.mapping.updateListen).then(null, null, function (response) {
var idea = new Idea(angular.fromJson(response.body).payload.Idea);
ServiceRepo.updateIdea(idea);
updateIdea(idea);
table.getTableParams().reload();
});

WsApi.listen(ideaRepo.mapping.deleteListen).then(null, null, function (response) {
ServiceRepo.removeIdeaById(angular.fromJson(response.body).payload.Long);
table.getTableParams().reload();
});
}
});

return ideaRepo;

});
});

0 comments on commit 74aa1b7

Please sign in to comment.