Commit 3b3f710f authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Implement config for disabling workspace configuration.

parent 52c7e449
......@@ -49,6 +49,7 @@ manager = local
#default_workspace_id = 1
[user]
change_workspaces = True
# user registration
# use $username and $userid variables
#registration.hook = ['useradd', '$username']
......
......@@ -106,7 +106,7 @@ class AjaxController(AbstractController):
@cherrypy.expose
@cherrypy.tools.ajax()
def addworkspace(self, name, host, login, port=None, key=None, cmd=None):
if not vispa.config("workspace", "allow_new_workspaces", True):
if not vispa.config("user", "change_workspaces", True):
raise MessageException("No permission to add a new Workspace!")
db = self.get("db")
user_id = self.get("user_id")
......@@ -126,6 +126,8 @@ class AjaxController(AbstractController):
@cherrypy.expose
@cherrypy.tools.ajax()
def deleteworkspace(self, wid):
if not vispa.config("user", "change_workspaces", True):
raise MessageException("No permission to delete a Workspace!")
db = cherrypy.request.db
# is workspace owned by the user?
workspace = Workspace.get_by_id(db, wid)
......@@ -205,43 +207,44 @@ class AjaxController(AbstractController):
if not workspace.is_valid():
raise MessageException("Workspace not valid")
@cherrypy.expose
@cherrypy.tools.json_in()
def setworkspacedata(self):
try:
json = cherrypy.request.json
user_id = self.get("user_id")
workspace_id = json[u"id"]
del json[u"id"]
# is workspace owned by the user?
workspace = Workspace.get_by_id(cherrypy.request.db, workspace_id)
if not isinstance(workspace, Workspace):
raise Exception("Unknown workspace!")
if not workspace.user_id or workspace.user_id != user_id:
raise Exception("No permission!")
# empty string means None
for key in json:
json[key] = json[key] or None
success = Workspace.update(cherrypy.request.db, workspace_id,
**json)
if not success:
raise Exception("Couldn't update the workspace data!")
return success(encode_json=True)
except Exception, e:
return fail(msg=str(e), encode_json=True)
# @cherrypy.expose
# @cherrypy.tools.json_in()
# def setworkspacedata(self):
# try:
@cherrypy.expose
def updateworkspacestate(self, wid, state):
try:
db = cherrypy.request.db
user_id = self.get("user_id")
success = WorkspaceState.update_state(db, wid, user_id,
json.loads(state))
if not success:
raise Exception("Unknown Workspace!")
return success(encode_json=True)
except Exception, e:
return fail(msg=str(e), encode_json=True)
# json = cherrypy.request.json
# user_id = self.get("user_id")
# workspace_id = json[u"id"]
# del json[u"id"]
# # is workspace owned by the user?
# workspace = Workspace.get_by_id(cherrypy.request.db, workspace_id)
# if not isinstance(workspace, Workspace):
# raise Exception("Unknown workspace!")
# if not workspace.user_id or workspace.user_id != user_id:
# raise Exception("No permission!")
# # empty string means None
# for key in json:
# json[key] = json[key] or None
# success = Workspace.update(cherrypy.request.db, workspace_id,
# **json)
# if not success:
# raise Exception("Couldn't update the workspace data!")
# return success(encode_json=True)
# except Exception, e:
# return fail(msg=str(e), encode_json=True)
# @cherrypy.expose
# def updateworkspacestate(self, wid, state):
# try:
# db = cherrypy.request.db
# user_id = self.get("user_id")
# success = WorkspaceState.update_state(db, wid, user_id,
# json.loads(state))
# if not success:
# raise Exception("Unknown Workspace!")
# return success(encode_json=True)
# except Exception, e:
# return fail(msg=str(e), encode_json=True)
@cherrypy.expose
def localuser(self):
......
......@@ -108,7 +108,7 @@ class RootController(AbstractController):
workspace_ids = JSON.dumps(workspace_ids)
workspace_data = self.workspace_data()
workspace_data = JSON.dumps(workspace_data)
# add_workspaces = vispa.config("workspace", "allow_new_workspaces", True)
change_workspaces = vispa.config("user", "change_workspaces", True)
data = {
"dev_mode" : dev_mode,
"username" : username,
......@@ -117,7 +117,7 @@ class RootController(AbstractController):
"use_websockets" : use_websockets,
"workspace_ids" : workspace_ids,
"workspace_data" : workspace_data,
# "add_workspaces" : add_workspaces,
"change_workspaces": change_workspaces,
"log_level" : client_log_level,
}
data.update(preferences)
......
......@@ -155,6 +155,13 @@ var Vispa = Emitter.extend({
this.workspaces.on("connectedWorkspace", toggleIcons);
this.workspaces.on("disconnectedWorkspace", toggleIcons);
// apply vispaUser.changeWorkspaces
if (!window.vispaUser.changeWorkspaces) {
$("#ws-menu-entry-add-ws").remove();
$("#ws-menu-entry-conf-ws").remove();
$("#ws-menu-entry-divide-ws").remove();
}
this.connectEvents();
return this;
......
......@@ -93,7 +93,8 @@
// store user data
window.vispaUser = {
name: "${username}"
name: "${username}",
changeWorkspaces: ${"true" if change_workspaces else "false"}
};
// use template variables to create the vispa config
......@@ -153,7 +154,7 @@
<span>Workspaces</span>
</button>
<ul class="dropdown-menu" id="workspaces-menu">
<li class="divider"></li>
<li class="divider" id="ws-menu-entry-divide-ws"></li>
<li>
<a href="#" id="ws-menu-entry-add-ws">
<i class="glyphicon glyphicon-plus"></i>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment