annotate sat/plugins/plugin_comp_file_sharing_management.py @ 2929:e0429ff7f6b6

plugin comp file sharing: file sharing management first draft: the new "component file sharing management" plugin add ad-hoc commands to changes permission of one or several shared files, delete one or more files, or regenerate thumbnails. This is a temporary plugin to make file sharing through a component usable with other entities, but should be removed (at least permission management and file deletion) in the future if we move on a pubsub based solution.
author Goffi <goffi@goffi.org>
date Sun, 28 Apr 2019 09:00:51 +0200
parents
children 0bafdbda7f5f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2929
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # SAT plugin to detect language (experimental)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 import os.path
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from functools import partial
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.i18n import _, D_
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat.core import exceptions
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat.core.constants import Const as C
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.core.log import getLogger
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from wokkel import data_form
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.internet import defer
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from twisted.words.protocols.jabber import jid
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 log = getLogger(__name__)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 PLUGIN_INFO = {
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34 C.PI_NAME: u"File Sharing Management",
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 C.PI_IMPORT_NAME: u"FILE_SHARING_MANAGEMENT",
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 C.PI_MODES: [C.PLUG_MODE_COMPONENT],
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 C.PI_TYPE: u"EXP",
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 C.PI_PROTOCOLS: [],
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39 C.PI_DEPENDENCIES: [u"XEP-0050", u"XEP-0264"],
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 C.PI_RECOMMENDATIONS: [],
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 C.PI_MAIN: u"FileSharingManagement",
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 C.PI_HANDLER: u"no",
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 C.PI_DESCRIPTION: _(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 u"Experimental handling of file management for file sharing. This plugins allows "
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 u"to change permissions of stored files/directories or remove them."
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 ),
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 }
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
48
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 NS_FILE_MANAGEMENT = u"https://salut-a-toi.org/protocol/file-management:0"
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 NS_FILE_MANAGEMENT_PERM = u"https://salut-a-toi.org/protocol/file-management:0#perm"
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 NS_FILE_MANAGEMENT_DELETE = u"https://salut-a-toi.org/protocol/file-management:0#delete"
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 NS_FILE_MANAGEMENT_THUMB = u"https://salut-a-toi.org/protocol/file-management:0#thumb"
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
54
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 class WorkflowError(Exception):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
56 """Raised when workflow can't be completed"""
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
57
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 def __init__(self, err_args):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 """
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 @param err_args(tuple): arguments to return to finish the command workflow
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 """
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 Exception.__init__(self)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 self.err_args = err_args
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
64
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 class FileSharingManagement(object):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 # This is a temporary way (Q&D) to handle stored files, a better way (using pubsub
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 # syntax?) should be elaborated and proposed as a standard.
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 def __init__(self, host):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 log.info(_(u"File Sharing Management plugin initialization"))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.host = host
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self._c = host.plugins["XEP-0050"]
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self._t = host.plugins["XEP-0264"]
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 self.files_path = host.getLocalPath(None, C.FILES_DIR, profile=False)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 def profileConnected(self, client):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 self._c.addAdHocCommand(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 client, self._onChangeFile, u"Change Permissions of File(s)",
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 node=NS_FILE_MANAGEMENT_PERM,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 allowed_magics=C.ENTITY_ALL,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 )
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 self._c.addAdHocCommand(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 client, self._onDeleteFile, u"Delete File(s)",
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 node=NS_FILE_MANAGEMENT_DELETE,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 allowed_magics=C.ENTITY_ALL,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 )
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self._c.addAdHocCommand(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 client, self._onGenThumbnails, u"Generate Thumbnails",
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 node=NS_FILE_MANAGEMENT_THUMB,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 allowed_magics=C.ENTITY_ALL,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 )
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
93
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 def _err(self, reason):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
95 """Helper method to get argument to return for error
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
96
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 workflow will be interrupted with an error note
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 @param reason(unicode): reason of the error
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 @return (tuple): arguments to use in defer.returnValue
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 """
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 status = self._c.STATUS.COMPLETED
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 payload = None
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 note = (self._c.NOTE.ERROR, reason)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 return payload, status, None, note
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
105
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 def _getRootArgs(self):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 """Create the form to select the file to use
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 @return (tuple): arguments to use in defer.returnValue
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 """
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 status = self._c.STATUS.EXECUTING
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 form = data_form.Form("form", title=u"File Management",
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 formNamespace=NS_FILE_MANAGEMENT)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
114
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 field = data_form.Field(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 "text-single", "path", required=True
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 )
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 form.addField(field)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 field = data_form.Field(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
121 "text-single", "namespace", required=False
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 )
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 form.addField(field)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 payload = form.toElement()
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 return payload, status, None, None
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 @defer.inlineCallbacks
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 def _getFileData(self, client, session_data, command_form):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 """Retrieve field requested in root form
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
131
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 "found_file" will also be set in session_data
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 @param command_form(data_form.Form): response to root form
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 @return (D(dict)): found file data
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 @raise WorkflowError: something is wrong
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 """
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 fields = command_form.fields
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 path = fields[u'path'].value.strip()
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 namespace = fields[u'namespace'].value or None
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 except KeyError:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 self._c.adHocError(self._c.ERROR.BAD_PAYLOAD)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
143
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 if not path:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 self._c.adHocError(self._c.ERROR.BAD_PAYLOAD)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
146
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 requestor = session_data[u'requestor']
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 requestor_bare = requestor.userhostJID()
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 path = path.rstrip(u'/')
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 parent_path, basename = os.path.split(path)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
151
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 # TODO: if parent_path and basename are empty, we ask for root directory
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 # this must be managed
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
154
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 found_files = yield self.host.memory.getFiles(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 client, requestor_bare, path=parent_path, name=basename,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 namespace=namespace)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 found_file = found_files[0]
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 except (exceptions.NotFound, IndexError):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 raise WorkflowError(self._err(_(u"file not found")))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 except exceptions.PermissionError:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 raise WorkflowError(self._err(_(u"forbidden")))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
164
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 if found_file['owner'] != requestor_bare:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 # only owner can manage files
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 log.warning(_(u"Only owner can manage files"))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 raise WorkflowError(self._err(_(u"forbidden")))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
169
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 session_data[u'found_file'] = found_file
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 session_data[u'namespace'] = namespace
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 defer.returnValue(found_file)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
173
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 def _updateReadPermission(self, access, allowed_jids):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 if not allowed_jids:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 if C.ACCESS_PERM_READ in access:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 del access[C.ACCESS_PERM_READ]
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 elif allowed_jids == u'PUBLIC':
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 access[C.ACCESS_PERM_READ] = {
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 u"type": C.ACCESS_TYPE_PUBLIC
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 }
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 else:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 access[C.ACCESS_PERM_READ] = {
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 u"type": C.ACCESS_TYPE_WHITELIST,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 u"jids": [j.full() for j in allowed_jids]
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 }
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
187
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 @defer.inlineCallbacks
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 def _updateDir(self, client, requestor, namespace, file_data, allowed_jids):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 """Recursively update permission of a directory and all subdirectories
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
191
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 @param file_data(dict): metadata of the file
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 @param allowed_jids(list[jid.JID]): list of entities allowed to read the file
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 """
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 assert file_data[u'type'] == C.FILE_TYPE_DIRECTORY
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 files_data = yield self.host.memory.getFiles(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 client, requestor, parent=file_data[u'id'], namespace=namespace)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
198
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 for file_data in files_data:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 if not file_data[u'access'].get(C.ACCESS_PERM_READ, {}):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 log.debug(u"setting {perm} read permission for {name}".format(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 perm=allowed_jids, name=file_data[u'name']))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 yield self.host.memory.fileUpdate(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 file_data[u'id'], u'access',
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 partial(self._updateReadPermission, allowed_jids=allowed_jids))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 if file_data[u'type'] == C.FILE_TYPE_DIRECTORY:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 yield self._updateDir(client, requestor, namespace, file_data, u'PUBLIC')
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
208
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 @defer.inlineCallbacks
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 def _onChangeFile(self, client, command_elt, session_data, action, node):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 x_elt = command_elt.elements(data_form.NS_X_DATA, "x").next()
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 command_form = data_form.Form.fromElement(x_elt)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 except StopIteration:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 command_form = None
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
216
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 found_file = session_data.get('found_file')
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 requestor = session_data[u'requestor']
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 requestor_bare = requestor.userhostJID()
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
220
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 if command_form is None or len(command_form.fields) == 0:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 # root request
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 defer.returnValue(self._getRootArgs())
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
224
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 elif found_file is None:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 # file selected, we retrieve it and ask for permissions
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 found_file = yield self._getFileData(client, session_data, command_form)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 except WorkflowError as e:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 defer.returnValue(e.err_args)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
231
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 # management request
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 if found_file[u'type'] == C.FILE_TYPE_DIRECTORY:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 instructions = D_(u"Please select permissions for this directory")
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 else:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 instructions = D_(u"Please select permissions for this file")
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
237
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 form = data_form.Form("form", title=u"File Management",
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 instructions=[instructions],
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 formNamespace=NS_FILE_MANAGEMENT)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 field = data_form.Field(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 "text-multi", "read_allowed", required=False,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 desc=u'list of jids allowed to read this file (beside yourself), or '
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 u'"PUBLIC" to let a public access'
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 )
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 read_access = found_file[u"access"].get(C.ACCESS_PERM_READ, {})
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 access_type = read_access.get(u'type', C.ACCESS_TYPE_WHITELIST)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 if access_type == C.ACCESS_TYPE_PUBLIC:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 field.values = [u'PUBLIC']
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 else:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 field.values = read_access.get('jids', [])
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 form.addField(field)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 if found_file[u'type'] == C.FILE_TYPE_DIRECTORY:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 field = data_form.Field(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 "boolean", "recursive", value=False, required=False,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 desc=u"Files under it will be made public to follow this dir "
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 u"permission (only if they don't have already a permission set)."
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 )
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 form.addField(field)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
260
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 status = self._c.STATUS.EXECUTING
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 payload = form.toElement()
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 defer.returnValue((payload, status, None, None))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
264
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 else:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 # final phase, we'll do permission change here
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 read_allowed = command_form.fields['read_allowed']
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 except KeyError:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 self._c.adHocError(self._c.ERROR.BAD_PAYLOAD)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
271
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 if read_allowed.value == u'PUBLIC':
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 allowed_jids = u'PUBLIC'
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 elif read_allowed.value.strip() == u'':
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 allowed_jids = None
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 else:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
278 allowed_jids = [jid.JID(v.strip()) for v in read_allowed.values]
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 except RuntimeError as e:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 log.warning(_(u"Can't use read_allowed values: {reason}").format(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 reason=e))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
282 self._c.adHocError(self._c.ERROR.BAD_PAYLOAD)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
283
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
284 if found_file[u'type'] == C.FILE_TYPE_FILE:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
285 yield self.host.memory.fileUpdate(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 found_file[u'id'], u'access',
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 partial(self._updateReadPermission, allowed_jids=allowed_jids))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 else:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 recursive = command_form.fields['recursive']
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 except KeyError:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 self._c.adHocError(self._c.ERROR.BAD_PAYLOAD)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 yield self.host.memory.fileUpdate(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 found_file[u'id'], u'access',
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
295 partial(self._updateReadPermission, allowed_jids=allowed_jids))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
296 if recursive:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 # we set all file under the directory as public (if they haven't
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 # already a permission set), so allowed entities of root directory
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
299 # can read them.
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 namespace = session_data[u'namespace']
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 yield self._updateDir(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 client, requestor_bare, namespace, found_file, u'PUBLIC')
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
303
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 # job done, we can end the session
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 status = self._c.STATUS.COMPLETED
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 payload = None
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 note = (self._c.NOTE.INFO, _(u"management session done"))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 defer.returnValue((payload, status, None, note))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
309
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 @defer.inlineCallbacks
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 def _onDeleteFile(self, client, command_elt, session_data, action, node):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 x_elt = command_elt.elements(data_form.NS_X_DATA, "x").next()
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
314 command_form = data_form.Form.fromElement(x_elt)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 except StopIteration:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 command_form = None
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
317
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 found_file = session_data.get('found_file')
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 requestor = session_data[u'requestor']
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 requestor_bare = requestor.userhostJID()
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
321
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 if command_form is None or len(command_form.fields) == 0:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
323 # root request
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 defer.returnValue(self._getRootArgs())
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
325
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 elif found_file is None:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 # file selected, we need confirmation before actually deleting
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
328 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
329 found_file = yield self._getFileData(client, session_data, command_form)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 except WorkflowError as e:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
331 defer.returnValue(e.err_args)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
332 if found_file[u'type'] == C.FILE_TYPE_DIRECTORY:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
333 msg = D_(u"Are you sure to delete directory {name} and all files and "
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
334 u"directories under it?").format(name=found_file[u'name'])
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
335 else:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 msg = D_(u"Are you sure to delete file {name}?"
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 .format(name=found_file[u'name']))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 form = data_form.Form("form", title=u"File Management",
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 instructions = [msg],
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 formNamespace=NS_FILE_MANAGEMENT)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 field = data_form.Field(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 "boolean", "confirm", value=False, required=True,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 desc=u"check this box to confirm"
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 )
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 form.addField(field)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 status = self._c.STATUS.EXECUTING
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 payload = form.toElement()
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 defer.returnValue((payload, status, None, None))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
349
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 else:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 # final phase, we'll do deletion here
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 confirmed = command_form.fields['confirm']
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 except KeyError:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 self._c.adHocError(self._c.ERROR.BAD_PAYLOAD)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
356 if not confirmed:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 note = None
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 else:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
359 recursive = found_file[u'type'] == C.FILE_TYPE_DIRECTORY
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 yield self.host.memory.fileDelete(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
361 client, requestor_bare, found_file[u'id'], recursive)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 note = (self._c.NOTE.INFO, _(u"file deleted"))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 status = self._c.STATUS.COMPLETED
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 payload = None
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
365 defer.returnValue((payload, status, None, note))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
366
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 def _updateThumbs(self, extra, thumbnails):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 extra[C.KEY_THUMBNAILS] = thumbnails
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
369
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
370 @defer.inlineCallbacks
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 def _genThumbs(self, client, requestor, namespace, file_data):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
372 """Recursively generate thumbnails
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
373
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
374 @param file_data(dict): metadata of the file
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 """
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
376 if file_data[u'type'] == C.FILE_TYPE_DIRECTORY:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 sub_files_data = yield self.host.memory.getFiles(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 client, requestor, parent=file_data[u'id'], namespace=namespace)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
379 for sub_file_data in sub_files_data:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
380 yield self._genThumbs(client, requestor, namespace, sub_file_data)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
381
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
382 elif file_data[u'type'] == C.FILE_TYPE_FILE:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
383 mime_type = file_data[u'mime_type']
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
384 file_path = os.path.join(self.files_path, file_data[u'file_hash'])
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
385 if mime_type is not None and mime_type.startswith(u"image"):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
386 thumbnails = []
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
387
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
388 for max_thumb_size in (self._t.SIZE_SMALL, self._t.SIZE_MEDIUM):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
389 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
390 thumb_size, thumb_id = yield self._t.generateThumbnail(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
391 file_path,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
392 max_thumb_size,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
393 #  we keep thumbnails for 6 months
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
394 60 * 60 * 24 * 31 * 6,
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
395 )
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
396 except Exception as e:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
397 log.warning(_(u"Can't create thumbnail: {reason}")
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
398 .format(reason=e))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
399 break
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
400 thumbnails.append({u"id": thumb_id, u"size": thumb_size})
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
401
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
402 yield self.host.memory.fileUpdate(
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
403 file_data[u'id'], u'extra',
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
404 partial(self._updateThumbs, thumbnails=thumbnails))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
405
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
406 log.info(u"thumbnails for [{file_name}] generated"
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
407 .format(file_name=file_data[u'name']))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
408
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
409 else:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
410 log.warning(u"unmanaged file type: {type_}".format(type_=file_data[u'type']))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
411
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
412 @defer.inlineCallbacks
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
413 def _onGenThumbnails(self, client, command_elt, session_data, action, node):
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
414 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
415 x_elt = command_elt.elements(data_form.NS_X_DATA, "x").next()
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
416 command_form = data_form.Form.fromElement(x_elt)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
417 except StopIteration:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
418 command_form = None
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
419
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
420 found_file = session_data.get('found_file')
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
421 requestor = session_data[u'requestor']
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
422
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
423 if command_form is None or len(command_form.fields) == 0:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
424 # root request
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
425 defer.returnValue(self._getRootArgs())
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
426
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
427 elif found_file is None:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
428 # file selected, we retrieve it and ask for permissions
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
429 try:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
430 found_file = yield self._getFileData(client, session_data, command_form)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
431 except WorkflowError as e:
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
432 defer.returnValue(e.err_args)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
433
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
434 log.info(u"Generating thumbnails as requested")
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
435 yield self._genThumbs(client, requestor, found_file[u'namespace'], found_file)
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
436
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
437 # job done, we can end the session
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
438 status = self._c.STATUS.COMPLETED
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
439 payload = None
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
440 note = (self._c.NOTE.INFO, _(u"thumbnails generated"))
e0429ff7f6b6 plugin comp file sharing: file sharing management first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
441 defer.returnValue((payload, status, None, note))