Add limited and protected permission

This commit is contained in:
蒼時弦也 2017-01-10 10:02:37 +08:00
parent c21fb8e2a0
commit 89b8ddeaba
5 changed files with 43 additions and 16 deletions

View File

@ -23,7 +23,7 @@ var logger = require("../logger.js");
var ot = require("../ot/index.js"); var ot = require("../ot/index.js");
// permission types // permission types
var permissionTypes = ["freely", "editable", "locked", "private"]; var permissionTypes = ["freely", "editable", "locked", "private", "limited", "protected"];
module.exports = function (sequelize, DataTypes) { module.exports = function (sequelize, DataTypes) {
var Note = sequelize.define("Note", { var Note = sequelize.define("Note", {

View File

@ -618,12 +618,12 @@ function ifMayEdit(socket, callback) {
case "freely": case "freely":
//not blocking anyone //not blocking anyone
break; break;
case "editable": case "editable": case: "limited":
//only login user can change //only login user can change
if (!socket.request.user || !socket.request.user.logged_in) if (!socket.request.user || !socket.request.user.logged_in)
mayEdit = false; mayEdit = false;
break; break;
case "locked": case "private": case "locked": case "private": case "protected":
//only owner can change //only owner can change
if (!note.owner || note.owner != socket.request.user.id) if (!note.owner || note.owner != socket.request.user.id)
mayEdit = false; mayEdit = false;

View File

@ -122,6 +122,11 @@ function checkViewPermission(req, note) {
return false; return false;
else else
return true; return true;
} else if (note.permission == 'limited' || note.permission == 'protected') {
if( !req.isAuthenticated() ) {
return false;
}
return true;
} else { } else {
return true; return true;
} }

View File

@ -857,7 +857,9 @@ window.ui = {
freely: $(".ui-permission-freely"), freely: $(".ui-permission-freely"),
editable: $(".ui-permission-editable"), editable: $(".ui-permission-editable"),
locked: $(".ui-permission-locked"), locked: $(".ui-permission-locked"),
private: $(".ui-permission-private") private: $(".ui-permission-private"),
limited: $(".ui-permission-limited"),
protected: $(".ui-permission-protected")
}, },
delete: $(".ui-delete-note") delete: $(".ui-delete-note")
}, },
@ -2247,6 +2249,14 @@ ui.infobar.permission.locked.click(function () {
ui.infobar.permission.private.click(function () { ui.infobar.permission.private.click(function () {
emitPermission("private"); emitPermission("private");
}); });
//limited
ui.infobar.permission.limited.click(function() {
emitPermission("limited");
});
//protected
ui.infobar.permission.protected.click(function() {
emitPermission("protected");
});
// delete note // delete note
ui.infobar.delete.click(function () { ui.infobar.delete.click(function () {
$('.delete-modal').modal('show'); $('.delete-modal').modal('show');
@ -2285,6 +2295,14 @@ function updatePermission(newPermission) {
label = '<i class="fa fa-hand-stop-o"></i> Private'; label = '<i class="fa fa-hand-stop-o"></i> Private';
title = "Only owner can view & edit"; title = "Only owner can view & edit";
break; break;
case "limited":
label = '<i class="fa fa-hand-shield"></i> Limited';
title = "Signed people can view and edit"
break;
case "protected":
label = '<i class="fa fa-hand-stop-o"></i> Protected';
title = "Signed people can view";
break;
} }
if (personalInfo.userid && owner && personalInfo.userid == owner) { if (personalInfo.userid && owner && personalInfo.userid == owner) {
label += ' <i class="fa fa-caret-down"></i>'; label += ' <i class="fa fa-caret-down"></i>';
@ -2302,6 +2320,7 @@ function havePermission() {
bool = true; bool = true;
break; break;
case "editable": case "editable":
case "limited":
if (!personalInfo.login) { if (!personalInfo.login) {
bool = false; bool = false;
} else { } else {
@ -2310,6 +2329,7 @@ function havePermission() {
break; break;
case "locked": case "locked":
case "private": case "private":
case "protected":
if (!owner || personalInfo.userid != owner) { if (!owner || personalInfo.userid != owner) {
bool = false; bool = false;
} else { } else {

View File

@ -19,6 +19,8 @@
<li class="ui-permission-editable"><a><i class="fa fa-shield fa-fw"></i> Editable - Signed people can edit</a></li> <li class="ui-permission-editable"><a><i class="fa fa-shield fa-fw"></i> Editable - Signed people can edit</a></li>
<li class="ui-permission-locked"><a><i class="fa fa-lock fa-fw"></i> Locked - Only owner can edit</a></li> <li class="ui-permission-locked"><a><i class="fa fa-lock fa-fw"></i> Locked - Only owner can edit</a></li>
<li class="ui-permission-private"><a><i class="fa fa-hand-stop-o fa-fw"></i> Private - Only owner can view &amp; edit</a></li> <li class="ui-permission-private"><a><i class="fa fa-hand-stop-o fa-fw"></i> Private - Only owner can view &amp; edit</a></li>
<li class="ui-permission-limited"><a><i class="fa fa-shield fa-fw"></i> Limited - Signed people can edit &amp; view</a></li>
<li class="ui-permission-protected"><a><i class="fa fa-hand-stop-o fa-fw"></i> Protected - Only owner can edit</a></li>
<li class="divider"></li> <li class="divider"></li>
<li class="ui-delete-note"><a><i class="fa fa-trash-o fa-fw"></i> Delete this note</a></li> <li class="ui-delete-note"><a><i class="fa fa-trash-o fa-fw"></i> Delete this note</a></li>
</ul> </ul>