Skip to content

Commit

Permalink
Allow Post Mods to view mod notes (#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
robdy authored and SnowPhoenix committed Jun 18, 2018
1 parent 48d5db1 commit 1b63a83
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions api/policies/isPostMod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (req, res, next) => (Users.hasModPermission(req.user, 'posts') && Users.hasModPermission(req.user, 'wiki')) ? next() : res.forbidden("Not post mod");
2 changes: 1 addition & 1 deletion api/services/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ exports.get = async function (requester, username) {
user.comments = result;
}));

if (Users.hasModPermission(requester, 'access')) {
if (Users.hasModPermission(requester, 'posts') && Users.hasModPermission(requester, 'wiki')) {
promises.push(ModNote.find({refUser: user.name}).sort({createdAt: 'desc'}).then(function (result) {
user.modNotes = result;
}));
Expand Down
6 changes: 3 additions & 3 deletions assets/views/home/modEdit.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a ng-href="/u/{{note.user}}">{{note.user}}</a>
<span class="pull-right">
{{note.createdAt | date: "medium"}}
<a href="#" ng-click="delNote(note.id)">
<a ng-controller="referenceCtrl" ng-if="user.isMod && user.modPermissions && user.modPermissions.includes('all')" href="#" ng-click="delNote(note.id)">
<span class="glyphicon glyphicon-trash"></span>
</a>
</span>
Expand All @@ -27,7 +27,7 @@
</div>
</div>
</div>
<div class="form-group">
<div class="form-group" ng-if="user.isMod && user.modPermissions && user.modPermissions.includes('all')">
<textarea class="form-control" ng-model="newStuff.newNote" ng-trim="false"
placeholder="Add Note with markdown"></textarea>
<div class="panel panel-default">
Expand All @@ -42,7 +42,7 @@
</div>


<div class="col-md-6">
<div class="col-md-6" ng-if="user.isMod && user.modPermissions && user.modPermissions.includes('all')">
<div class="form-group">
<label class="col-sm-3 control-label">Introduction:</label>

Expand Down
4 changes: 2 additions & 2 deletions assets/views/home/reference.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<li class="active"><a href="#references" role="tab" data-toggle="tab">References</a></li>
<li><a href="#comments" role="tab" data-toggle="tab">Comments ({{refUser.comments.length}})</a></li>
<li><a href="#info" role="tab" data-toggle="tab">Information</a></li>
<li ng-if="user.isMod && user.modPermissions && user.modPermissions.includes('all')"><a href="#modEdit" role="tab" data-toggle="tab">Moderation ({{refUser.modNotes.length}})</a></li>
<li ng-if="user.isMod && user.modPermissions && (user.modPermissions.includes('all') || (user.modPermissions.includes('posts') && user.modPermissions.includes('wiki')))"><a href="#modEdit" role="tab" data-toggle="tab">Moderation ({{refUser.modNotes.length}})</a></li>
</ul>

<div class="tab-content">
Expand Down Expand Up @@ -75,7 +75,7 @@
<div class="tab-pane" id="info">
<%- partial('profileInfo.ejs') %>
</div>
<div class="tab-pane" id="modEdit" ng-if="user.isMod && user.modPermissions.includes('all')">
<div class="tab-pane" id="modEdit" ng-if="user.isMod && (user.modPermissions.includes('all') || (user.modPermissions.includes('posts') && user.modPermissions.includes('wiki')))">
<%- partial('modEdit.ejs') %>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions config/policies.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
const anyone = ['passport'];
const user = ['passport', 'sessionAuth'];
const flairMod = ['passport', 'sessionAuth', 'isFlairMod'];
const postMod = ['passport', 'sessionAuth', 'isPostMod'];
const admin = ['passport', 'sessionAuth', 'isAdmin'];

module.exports.policies = {
Expand Down Expand Up @@ -75,5 +76,10 @@ module.exports.policies = {
edit: user,
mine: user,
get: anyone
},

ModNoteController: {
'*': admin,
find: postMod
}
};

0 comments on commit 1b63a83

Please sign in to comment.