Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
3pia
VISPA
VISPA web
Commits
0d023cce
Commit
0d023cce
authored
Apr 29, 2015
by
Marcel Rieger
Browse files
Add method tool to ajax controllers.
parent
e5ff294a
Changes
2
Show whitespace changes
Inline
Side-by-side
vispa/controller/ajax.py
View file @
0d023cce
...
...
@@ -19,34 +19,41 @@ logger = logging.getLogger(__name__)
class
AjaxController
(
AbstractController
):
def
__init__
(
self
,
root
):
AbstractController
.
__init__
(
self
,
mount_static
=
False
)
super
(
AjaxController
,
self
).
__init__
(
mount_static
=
False
)
self
.
_root
=
root
self
.
fs
=
FSAjaxController
()
@
cherrypy
.
expose
@
cherrypy
.
tools
.
user
(
on
=
False
)
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
login
(
self
,
username
,
password
):
db
=
cherrypy
.
request
.
db
user
=
User
.
login
(
db
,
username
,
password
)
cherrypy
.
session
[
"user_id"
]
=
unicode
(
user
.
id
)
cherrypy
.
session
[
"user_name"
]
=
username
user
=
User
.
login
(
cherrypy
.
request
.
db
,
username
,
password
)
cherrypy
.
session
[
"user_id"
]
=
user
.
id
cherrypy
.
session
[
"user_name"
]
=
user
.
name
return
{
"userId"
:
user
.
id
,
"sessionId"
:
cherrypy
.
session
.
id
}
@
cherrypy
.
expose
@
cherrypy
.
tools
.
user
(
on
=
False
)
@
cherrypy
.
tools
.
allow
(
methods
=
[
"POST"
]
)
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
register
(
self
,
username
,
email
):
db
=
cherrypy
.
request
.
db
user
=
User
.
register
(
db
,
username
,
email
)
if
vispa
.
config
(
"web"
,
"registration.sendmail"
,
False
):
user
=
User
.
register
(
cherrypy
.
request
.
db
,
username
,
email
)
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
)
elif
vispa
.
config
(
"web"
,
"registration.autoactive"
,
True
):
return
{
"hash"
:
user
.
hash
}
return
{
"hash"
:
None
}
return
{
"hash"
:
None
}
@
cherrypy
.
expose
@
cherrypy
.
tools
.
user
(
on
=
False
)
@
cherrypy
.
tools
.
allow
(
methods
=
[
"POST"
]
)
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
forgotpassword
(
self
,
username
):
if
vispa
.
config
(
"web"
,
"forgot.use"
,
False
)
and
not
cherrypy
.
session
.
get
(
"is_guest"
,
False
):
User
.
forgot_password
(
cherrypy
.
request
.
db
,
username
)
...
...
@@ -55,6 +62,7 @@ class AjaxController(AbstractController):
@
cherrypy
.
expose
@
cherrypy
.
tools
.
user
(
on
=
False
)
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
setpassword
(
self
,
hash
,
password
):
user
=
User
.
set_password
(
cherrypy
.
request
.
db
,
hash
,
password
)
if
user
.
active
():
...
...
@@ -62,6 +70,7 @@ class AjaxController(AbstractController):
cherrypy
.
session
[
"user_name"
]
=
user
.
name
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
setvispapreference
(
self
,
name
,
value
=
u
"{}"
):
db
=
cherrypy
.
request
.
db
user_id
=
self
.
get
(
"user_id"
)
...
...
@@ -69,6 +78,7 @@ class AjaxController(AbstractController):
VispaPreference
.
set_value
(
db
,
user_id
,
name
,
value
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
setextensionpreference
(
self
,
name
,
value
=
u
"{}"
):
db
=
cherrypy
.
request
.
db
user_id
=
self
.
get
(
"user_id"
)
...
...
@@ -76,18 +86,21 @@ class AjaxController(AbstractController):
ExtensionPreference
.
set_value
(
db
,
user_id
,
name
,
value
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
setvispashortcuts
(
self
,
name
,
value
=
u
"{}"
):
db
=
cherrypy
.
request
.
db
user_id
=
self
.
get
(
"user_id"
)
VispaShortcuts
.
set_value
(
db
,
user_id
,
name
,
value
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
setextensionshortcuts
(
self
,
name
,
value
=
u
"{}"
):
db
=
cherrypy
.
request
.
db
user_id
=
self
.
get
(
"user_id"
)
ExtensionShortcuts
.
set_value
(
db
,
user_id
,
name
,
value
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
addworkspace
(
self
,
name
,
host
,
login
,
key
=
None
,
cmd
=
None
):
if
not
vispa
.
config
(
"workspace"
,
"add"
,
True
):
raise
AjaxException
(
"No permission to add a new Workspace!"
)
...
...
@@ -108,6 +121,7 @@ class AjaxController(AbstractController):
return
self
.
_root
.
workspace_data
(
workspace
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
deleteworkspace
(
self
,
wid
):
if
not
vispa
.
config
(
"workspace"
,
"add"
,
True
):
raise
AjaxException
(
"No permission to delete a Workspace!"
)
...
...
@@ -127,6 +141,7 @@ class AjaxController(AbstractController):
raise
AjaxException
(
"Couldn't remove this Workspace!"
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
connectworkspace
(
self
,
wid
,
password
=
None
):
db
=
cherrypy
.
request
.
db
user
=
cherrypy
.
request
.
user
...
...
@@ -140,6 +155,7 @@ class AjaxController(AbstractController):
vispa
.
workspace
.
connect
(
workspace
,
user
,
db
,
password
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
disconnectworkspace
(
self
,
wid
):
db
=
cherrypy
.
request
.
db
user
=
cherrypy
.
request
.
user
...
...
@@ -153,6 +169,7 @@ class AjaxController(AbstractController):
vispa
.
workspace
.
disconnect
(
workspace
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
getworkspacedata
(
self
,
wid
=
None
):
workspace
=
None
if
wid
:
...
...
@@ -162,6 +179,7 @@ class AjaxController(AbstractController):
return
self
.
_root
.
workspace_data
(
workspace
=
workspace
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
getworkspacestate
(
self
,
wid
):
db
=
cherrypy
.
request
.
db
userid
=
cherrypy
.
request
.
user
.
id
...
...
@@ -169,6 +187,7 @@ class AjaxController(AbstractController):
return
WorkspaceState
.
get_state
(
db
,
wid
,
userid
)
or
"{}"
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
setworkspacestate
(
self
,
wid
,
state
):
db
=
cherrypy
.
request
.
db
userid
=
cherrypy
.
request
.
user
.
id
...
...
@@ -190,6 +209,7 @@ class AjaxController(AbstractController):
logger
.
info
(
"Server uid: %s"
%
server_uid
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
feedback
(
self
,
content
,
anonymous
):
feedback_address
=
vispa
.
config
(
"web"
,
"feedback.address"
,
""
)
if
feedback_address
==
""
:
...
...
vispa/controller/filesystem.py
View file @
0d023cce
...
...
@@ -43,6 +43,7 @@ class FSController(AbstractController):
@
cherrypy
.
expose
@
cherrypy
.
tools
.
ajax
(
on
=
False
)
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
getfile
(
self
,
path
,
download
=
None
,
**
kwargs
):
fs
=
self
.
get
(
'fs'
)
stats
=
fs
.
stat
(
path
)
...
...
@@ -78,6 +79,7 @@ class FSController(AbstractController):
@
cherrypy
.
expose
@
cherrypy
.
tools
.
ajax
(
on
=
False
)
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
thumbnail
(
self
,
path
,
width
=
100
,
height
=
100
,
**
kwargs
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -91,6 +93,7 @@ class FSController(AbstractController):
class
FSAjaxController
(
AbstractController
):
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
exists
(
self
,
path
,
filetype
=
None
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -104,6 +107,7 @@ class FSAjaxController(AbstractController):
return
"Failed"
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
filecount
(
self
,
path
,
watch_id
=
None
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -126,6 +130,7 @@ class FSAjaxController(AbstractController):
@
cherrypy
.
expose
@
cherrypy
.
tools
.
ajax
(
encoded
=
True
)
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
filelist
(
self
,
path
,
filefilter
=
None
,
reverse
=
False
,
watch_id
=
None
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -141,6 +146,7 @@ class FSAjaxController(AbstractController):
watch_id
=
watch_id
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
createfolder
(
self
,
path
,
name
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -149,6 +155,7 @@ class FSAjaxController(AbstractController):
fs
.
create_folder
(
path
,
name
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
createfile
(
self
,
path
,
name
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -157,6 +164,7 @@ class FSAjaxController(AbstractController):
fs
.
create_file
(
path
,
name
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
rename
(
self
,
path
,
name
,
new_name
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -164,6 +172,7 @@ class FSAjaxController(AbstractController):
return
fs
.
rename
(
path
,
name
,
new_name
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
remove
(
self
,
path
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -179,6 +188,7 @@ class FSAjaxController(AbstractController):
return
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
move
(
self
,
source
,
destination
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -190,6 +200,7 @@ class FSAjaxController(AbstractController):
fs
.
move
(
source
,
destination
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
compress
(
self
,
path
,
paths
,
name
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -200,6 +211,7 @@ class FSAjaxController(AbstractController):
fs
.
compress
(
path
,
paths
,
name
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
decompress
(
self
,
file
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -207,6 +219,7 @@ class FSAjaxController(AbstractController):
fs
.
decompress
(
file
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
paste
(
self
,
path
,
paths
,
cut
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -220,6 +233,7 @@ class FSAjaxController(AbstractController):
return
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
upload
(
self
,
*
args
,
**
kwargs
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -258,6 +272,7 @@ class FSAjaxController(AbstractController):
append
=
True
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
isbrowserfile
(
self
,
path
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -272,6 +287,7 @@ class FSAjaxController(AbstractController):
return
str
(
e
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
getsuggestions
(
self
,
path
,
length
=
10
,
append_hidden
=
True
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -287,6 +303,7 @@ class FSAjaxController(AbstractController):
@
cherrypy
.
expose
@
cherrypy
.
tools
.
ajax
(
encoded
=
True
)
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
save_file
(
self
,
path
,
content
,
watch_id
=
None
,
utf8
=
False
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -298,6 +315,7 @@ class FSAjaxController(AbstractController):
@
cherrypy
.
expose
@
cherrypy
.
tools
.
ajax
(
encoded
=
True
)
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
get_file
(
self
,
path
,
watch_id
=
None
,
utf8
=
False
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -308,6 +326,7 @@ class FSAjaxController(AbstractController):
watch_id
=
watch_id
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
watch
(
self
,
path
,
watch_id
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -322,6 +341,7 @@ class FSAjaxController(AbstractController):
return
{
"success"
:
not
err
}
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
unwatch
(
self
,
watch_id
=
None
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -336,6 +356,7 @@ class FSAjaxController(AbstractController):
@
cherrypy
.
expose
@
cherrypy
.
tools
.
ajax
(
encoded
=
True
)
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
get_workspaceini
(
self
,
request
,
fail_on_missing
=
False
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -344,6 +365,7 @@ class FSAjaxController(AbstractController):
return
fs
.
get_workspaceini
(
request
,
fail_on_missing
=
fail_on_missing
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"POST"
)
def
set_workspaceini
(
self
,
request
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -355,6 +377,7 @@ class FSAjaxController(AbstractController):
return
{
"success"
:
not
err
}
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
expand
(
self
,
path
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
@@ -365,6 +388,7 @@ class FSAjaxController(AbstractController):
return
fs
.
expand
(
path
)
@
cherrypy
.
expose
@
cherrypy
.
tools
.
method
(
accept
=
"GET"
)
def
checkPermissions
(
self
,
path
):
self
.
release_session
()
fs
=
self
.
get
(
'fs'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment