Skip to content

Commit

Permalink
Fixed a regression with postin file actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Kraft committed Jan 22, 2024
1 parent 50d4be0 commit 6b8390f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
11 changes: 11 additions & 0 deletions odmf/webpage/filemanager/filehandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from ...config import conf
from . import fileactions as fa
from ..markdown import MarkDown
from ..auth import Level


markdown = MarkDown()

Expand Down Expand Up @@ -88,6 +90,15 @@ def get_action_buttons(self, path: Path):
action.check(path)
return '\n'.join(action.html(path) for action in self.actions if action.check(path))

def post_action(self, actionname: str, path: str, userlevel: Level):
for action in self.actions:
if action.name == actionname:
if userlevel >= action.access_level:
return action.post(path)
else:
raise ValueError('Invalid privileges')



class TextFileHandler(BaseFileHandler):
icon = 'file-alt'
Expand Down
17 changes: 8 additions & 9 deletions odmf/webpage/filemanager/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,16 @@ def write_to_file(self, path, text):
@expose_for()
@web.method.post
def action(self, path, action: str):
from ..auth import users, User, Level
from ..auth import users
path = Path(path)
handler = self.filehandler[path]
try:
action: fh.FileAction = handler.actions[action]
except KeyError:
raise DownloadPageError('not enough actions available')
if users.current.level < action.access_level:
required_group = Level(action.access_level)
raise DownloadPageError(path, 403,f'you need to be {required_group.name} for {action}')
newpath = action(path)
msg = {'msg': f'{action} on {path} successful'}
newpath = handler.post_action(action, path, users.current.level)
except ValueError:
raise DownloadPageError(path, 403,f'not enough privileges for {action} on {path}')
if newpath:
msg = {'msg': f'{action} on {path} successful'}
else:
msg = {'error': f'{action} on {path} not available'}
return f'{newpath.href}?{urlencode(msg)}'

0 comments on commit 6b8390f

Please sign in to comment.