Commit 0d023cce authored by Marcel Rieger's avatar Marcel Rieger
Browse files

Add method tool to ajax controllers.

parent e5ff294a
...@@ -19,34 +19,41 @@ logger = logging.getLogger(__name__) ...@@ -19,34 +19,41 @@ logger = logging.getLogger(__name__)
class AjaxController(AbstractController): class AjaxController(AbstractController):
def __init__(self, root): def __init__(self, root):
AbstractController.__init__(self, mount_static=False) super(AjaxController, self).__init__(mount_static=False)
self._root = root self._root = root
self.fs = FSAjaxController() self.fs = FSAjaxController()
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.user(on=False) @cherrypy.tools.user(on=False)
@cherrypy.tools.method(accept="POST")
def login(self, username, password): def login(self, username, password):
db = cherrypy.request.db user = User.login(cherrypy.request.db, username, password)
user = User.login(db, username, password)
cherrypy.session["user_id"] = unicode(user.id) cherrypy.session["user_id"] = user.id
cherrypy.session["user_name"] = username cherrypy.session["user_name"] = user.name
return { "userId": user.id, "sessionId": cherrypy.session.id }
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.user(on=False) @cherrypy.tools.user(on=False)
@cherrypy.tools.allow(methods=["POST"]) @cherrypy.tools.method(accept="POST")
def register(self, username, email): def register(self, username, email):
db = cherrypy.request.db user = User.register(cherrypy.request.db, username, email)
user = User.register(db, username, email)
if vispa.config("web", "registration.sendmail", False): if vispa.config("web", "registration.autoactive", True):
return { "hash": user.hash }
elif vispa.config("web", "registration.sendmail", False):
User.send_registration_mail(user.name, user.email, user.hash) User.send_registration_mail(user.name, user.email, user.hash)
elif vispa.config("web", "registration.autoactive", True):
return {"hash": user.hash} return { "hash": None }
return {"hash": None}
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.user(on=False) @cherrypy.tools.user(on=False)
@cherrypy.tools.allow(methods=["POST"]) @cherrypy.tools.method(accept="POST")
def forgotpassword(self, username): def forgotpassword(self, username):
if vispa.config("web", "forgot.use", False) and not cherrypy.session.get("is_guest", False): if vispa.config("web", "forgot.use", False) and not cherrypy.session.get("is_guest", False):
User.forgot_password(cherrypy.request.db, username) User.forgot_password(cherrypy.request.db, username)
...@@ -55,6 +62,7 @@ class AjaxController(AbstractController): ...@@ -55,6 +62,7 @@ class AjaxController(AbstractController):
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.user(on=False) @cherrypy.tools.user(on=False)
@cherrypy.tools.method(accept="POST")
def setpassword(self, hash, password): def setpassword(self, hash, password):
user = User.set_password(cherrypy.request.db, hash, password) user = User.set_password(cherrypy.request.db, hash, password)
if user.active(): if user.active():
...@@ -62,6 +70,7 @@ class AjaxController(AbstractController): ...@@ -62,6 +70,7 @@ class AjaxController(AbstractController):
cherrypy.session["user_name"] = user.name cherrypy.session["user_name"] = user.name
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def setvispapreference(self, name, value=u"{}"): def setvispapreference(self, name, value=u"{}"):
db = cherrypy.request.db db = cherrypy.request.db
user_id = self.get("user_id") user_id = self.get("user_id")
...@@ -69,6 +78,7 @@ class AjaxController(AbstractController): ...@@ -69,6 +78,7 @@ class AjaxController(AbstractController):
VispaPreference.set_value(db, user_id, name, value) VispaPreference.set_value(db, user_id, name, value)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def setextensionpreference(self, name, value=u"{}"): def setextensionpreference(self, name, value=u"{}"):
db = cherrypy.request.db db = cherrypy.request.db
user_id = self.get("user_id") user_id = self.get("user_id")
...@@ -76,18 +86,21 @@ class AjaxController(AbstractController): ...@@ -76,18 +86,21 @@ class AjaxController(AbstractController):
ExtensionPreference.set_value(db, user_id, name, value) ExtensionPreference.set_value(db, user_id, name, value)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def setvispashortcuts(self, name, value=u"{}"): def setvispashortcuts(self, name, value=u"{}"):
db = cherrypy.request.db db = cherrypy.request.db
user_id = self.get("user_id") user_id = self.get("user_id")
VispaShortcuts.set_value(db, user_id, name, value) VispaShortcuts.set_value(db, user_id, name, value)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def setextensionshortcuts(self, name, value=u"{}"): def setextensionshortcuts(self, name, value=u"{}"):
db = cherrypy.request.db db = cherrypy.request.db
user_id = self.get("user_id") user_id = self.get("user_id")
ExtensionShortcuts.set_value(db, user_id, name, value) ExtensionShortcuts.set_value(db, user_id, name, value)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def addworkspace(self, name, host, login, key=None, cmd=None): def addworkspace(self, name, host, login, key=None, cmd=None):
if not vispa.config("workspace", "add", True): if not vispa.config("workspace", "add", True):
raise AjaxException("No permission to add a new Workspace!") raise AjaxException("No permission to add a new Workspace!")
...@@ -108,6 +121,7 @@ class AjaxController(AbstractController): ...@@ -108,6 +121,7 @@ class AjaxController(AbstractController):
return self._root.workspace_data(workspace) return self._root.workspace_data(workspace)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def deleteworkspace(self, wid): def deleteworkspace(self, wid):
if not vispa.config("workspace", "add", True): if not vispa.config("workspace", "add", True):
raise AjaxException("No permission to delete a Workspace!") raise AjaxException("No permission to delete a Workspace!")
...@@ -127,6 +141,7 @@ class AjaxController(AbstractController): ...@@ -127,6 +141,7 @@ class AjaxController(AbstractController):
raise AjaxException("Couldn't remove this Workspace!") raise AjaxException("Couldn't remove this Workspace!")
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def connectworkspace(self, wid, password=None): def connectworkspace(self, wid, password=None):
db = cherrypy.request.db db = cherrypy.request.db
user = cherrypy.request.user user = cherrypy.request.user
...@@ -140,6 +155,7 @@ class AjaxController(AbstractController): ...@@ -140,6 +155,7 @@ class AjaxController(AbstractController):
vispa.workspace.connect(workspace, user, db, password) vispa.workspace.connect(workspace, user, db, password)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def disconnectworkspace(self, wid): def disconnectworkspace(self, wid):
db = cherrypy.request.db db = cherrypy.request.db
user = cherrypy.request.user user = cherrypy.request.user
...@@ -153,6 +169,7 @@ class AjaxController(AbstractController): ...@@ -153,6 +169,7 @@ class AjaxController(AbstractController):
vispa.workspace.disconnect(workspace) vispa.workspace.disconnect(workspace)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="GET")
def getworkspacedata(self, wid=None): def getworkspacedata(self, wid=None):
workspace = None workspace = None
if wid: if wid:
...@@ -162,6 +179,7 @@ class AjaxController(AbstractController): ...@@ -162,6 +179,7 @@ class AjaxController(AbstractController):
return self._root.workspace_data(workspace=workspace) return self._root.workspace_data(workspace=workspace)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="GET")
def getworkspacestate(self, wid): def getworkspacestate(self, wid):
db = cherrypy.request.db db = cherrypy.request.db
userid = cherrypy.request.user.id userid = cherrypy.request.user.id
...@@ -169,6 +187,7 @@ class AjaxController(AbstractController): ...@@ -169,6 +187,7 @@ class AjaxController(AbstractController):
return WorkspaceState.get_state(db, wid, userid) or "{}" return WorkspaceState.get_state(db, wid, userid) or "{}"
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def setworkspacestate(self, wid, state): def setworkspacestate(self, wid, state):
db = cherrypy.request.db db = cherrypy.request.db
userid = cherrypy.request.user.id userid = cherrypy.request.user.id
...@@ -190,6 +209,7 @@ class AjaxController(AbstractController): ...@@ -190,6 +209,7 @@ class AjaxController(AbstractController):
logger.info("Server uid: %s" % server_uid) logger.info("Server uid: %s" % server_uid)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def feedback(self, content, anonymous): def feedback(self, content, anonymous):
feedback_address = vispa.config("web", "feedback.address", "") feedback_address = vispa.config("web", "feedback.address", "")
if feedback_address == "": if feedback_address == "":
......
...@@ -43,6 +43,7 @@ class FSController(AbstractController): ...@@ -43,6 +43,7 @@ class FSController(AbstractController):
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.ajax(on=False) @cherrypy.tools.ajax(on=False)
@cherrypy.tools.method(accept="GET")
def getfile(self, path, download=None, **kwargs): def getfile(self, path, download=None, **kwargs):
fs = self.get('fs') fs = self.get('fs')
stats = fs.stat(path) stats = fs.stat(path)
...@@ -78,6 +79,7 @@ class FSController(AbstractController): ...@@ -78,6 +79,7 @@ class FSController(AbstractController):
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.ajax(on=False) @cherrypy.tools.ajax(on=False)
@cherrypy.tools.method(accept="GET")
def thumbnail(self, path, width=100, height=100, **kwargs): def thumbnail(self, path, width=100, height=100, **kwargs):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -91,6 +93,7 @@ class FSController(AbstractController): ...@@ -91,6 +93,7 @@ class FSController(AbstractController):
class FSAjaxController(AbstractController): class FSAjaxController(AbstractController):
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="GET")
def exists(self, path, filetype=None): def exists(self, path, filetype=None):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -104,6 +107,7 @@ class FSAjaxController(AbstractController): ...@@ -104,6 +107,7 @@ class FSAjaxController(AbstractController):
return "Failed" return "Failed"
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="GET")
def filecount(self, path, watch_id=None): def filecount(self, path, watch_id=None):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -126,6 +130,7 @@ class FSAjaxController(AbstractController): ...@@ -126,6 +130,7 @@ class FSAjaxController(AbstractController):
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.ajax(encoded=True) @cherrypy.tools.ajax(encoded=True)
@cherrypy.tools.method(accept="GET")
def filelist(self, path, filefilter=None, reverse=False, watch_id=None): def filelist(self, path, filefilter=None, reverse=False, watch_id=None):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -141,6 +146,7 @@ class FSAjaxController(AbstractController): ...@@ -141,6 +146,7 @@ class FSAjaxController(AbstractController):
watch_id=watch_id) watch_id=watch_id)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def createfolder(self, path, name): def createfolder(self, path, name):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -149,6 +155,7 @@ class FSAjaxController(AbstractController): ...@@ -149,6 +155,7 @@ class FSAjaxController(AbstractController):
fs.create_folder(path, name) fs.create_folder(path, name)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def createfile(self, path, name): def createfile(self, path, name):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -157,6 +164,7 @@ class FSAjaxController(AbstractController): ...@@ -157,6 +164,7 @@ class FSAjaxController(AbstractController):
fs.create_file(path, name) fs.create_file(path, name)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def rename(self, path, name, new_name): def rename(self, path, name, new_name):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -164,6 +172,7 @@ class FSAjaxController(AbstractController): ...@@ -164,6 +172,7 @@ class FSAjaxController(AbstractController):
return fs.rename(path, name, new_name) return fs.rename(path, name, new_name)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def remove(self, path): def remove(self, path):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -179,6 +188,7 @@ class FSAjaxController(AbstractController): ...@@ -179,6 +188,7 @@ class FSAjaxController(AbstractController):
return return
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def move(self, source, destination): def move(self, source, destination):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -190,6 +200,7 @@ class FSAjaxController(AbstractController): ...@@ -190,6 +200,7 @@ class FSAjaxController(AbstractController):
fs.move(source, destination) fs.move(source, destination)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def compress(self, path, paths, name): def compress(self, path, paths, name):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -200,6 +211,7 @@ class FSAjaxController(AbstractController): ...@@ -200,6 +211,7 @@ class FSAjaxController(AbstractController):
fs.compress(path, paths, name) fs.compress(path, paths, name)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def decompress(self, file): def decompress(self, file):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -207,6 +219,7 @@ class FSAjaxController(AbstractController): ...@@ -207,6 +219,7 @@ class FSAjaxController(AbstractController):
fs.decompress(file) fs.decompress(file)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def paste(self, path, paths, cut): def paste(self, path, paths, cut):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -220,6 +233,7 @@ class FSAjaxController(AbstractController): ...@@ -220,6 +233,7 @@ class FSAjaxController(AbstractController):
return return
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def upload(self, *args, **kwargs): def upload(self, *args, **kwargs):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -258,6 +272,7 @@ class FSAjaxController(AbstractController): ...@@ -258,6 +272,7 @@ class FSAjaxController(AbstractController):
append = True append = True
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="GET")
def isbrowserfile(self, path): def isbrowserfile(self, path):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -272,6 +287,7 @@ class FSAjaxController(AbstractController): ...@@ -272,6 +287,7 @@ class FSAjaxController(AbstractController):
return str(e) return str(e)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="GET")
def getsuggestions(self, path, length=10, append_hidden=True): def getsuggestions(self, path, length=10, append_hidden=True):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -287,6 +303,7 @@ class FSAjaxController(AbstractController): ...@@ -287,6 +303,7 @@ class FSAjaxController(AbstractController):
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.ajax(encoded=True) @cherrypy.tools.ajax(encoded=True)
@cherrypy.tools.method(accept="POST")
def save_file(self, path, content, watch_id=None, utf8=False): def save_file(self, path, content, watch_id=None, utf8=False):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -298,6 +315,7 @@ class FSAjaxController(AbstractController): ...@@ -298,6 +315,7 @@ class FSAjaxController(AbstractController):
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.ajax(encoded=True) @cherrypy.tools.ajax(encoded=True)
@cherrypy.tools.method(accept="GET")
def get_file(self, path, watch_id=None, utf8=False): def get_file(self, path, watch_id=None, utf8=False):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -308,6 +326,7 @@ class FSAjaxController(AbstractController): ...@@ -308,6 +326,7 @@ class FSAjaxController(AbstractController):
watch_id=watch_id) watch_id=watch_id)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def watch(self, path, watch_id): def watch(self, path, watch_id):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -322,6 +341,7 @@ class FSAjaxController(AbstractController): ...@@ -322,6 +341,7 @@ class FSAjaxController(AbstractController):
return {"success": not err} return {"success": not err}
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def unwatch(self, watch_id=None): def unwatch(self, watch_id=None):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -336,6 +356,7 @@ class FSAjaxController(AbstractController): ...@@ -336,6 +356,7 @@ class FSAjaxController(AbstractController):
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.ajax(encoded=True) @cherrypy.tools.ajax(encoded=True)
@cherrypy.tools.method(accept="GET")
def get_workspaceini(self, request, fail_on_missing=False): def get_workspaceini(self, request, fail_on_missing=False):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -344,6 +365,7 @@ class FSAjaxController(AbstractController): ...@@ -344,6 +365,7 @@ class FSAjaxController(AbstractController):
return fs.get_workspaceini(request, fail_on_missing=fail_on_missing) return fs.get_workspaceini(request, fail_on_missing=fail_on_missing)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="POST")
def set_workspaceini(self, request): def set_workspaceini(self, request):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -355,6 +377,7 @@ class FSAjaxController(AbstractController): ...@@ -355,6 +377,7 @@ class FSAjaxController(AbstractController):
return {"success": not err} return {"success": not err}
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="GET")
def expand(self, path): def expand(self, path):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
...@@ -365,6 +388,7 @@ class FSAjaxController(AbstractController): ...@@ -365,6 +388,7 @@ class FSAjaxController(AbstractController):
return fs.expand(path) return fs.expand(path)
@cherrypy.expose @cherrypy.expose
@cherrypy.tools.method(accept="GET")
def checkPermissions(self, path): def checkPermissions(self, path):
self.release_session() self.release_session()
fs = self.get('fs') fs = self.get('fs')
......
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