comparison libervia/pages/photos/new/page_meta.py @ 1356:39719ff4fcad

pages (photos/new): fix permissions: "/albums" path is created with `open` access model if it doesn't already exist. The album itself is created as a sub-directory with a `whitelist` access model, if it doesn't already exist (otherwise the album is just added in list of interests).
author Goffi <goffi@goffi.org>
date Thu, 17 Sep 2020 16:44:54 +0200
parents 3a1cb3c5702f
children 106bae41f5c8
comparison
equal deleted inserted replaced
1355:6f342b36871c 1356:39719ff4fcad
3 from libervia.server.constants import Const as C 3 from libervia.server.constants import Const as C
4 from twisted.internet import defer 4 from twisted.internet import defer
5 from sat.core.log import getLogger 5 from sat.core.log import getLogger
6 from sat.core.i18n import D_ 6 from sat.core.i18n import D_
7 from sat.core import exceptions 7 from sat.core import exceptions
8 from sat_frontends.bridge.bridge_frontend import BridgeException
8 9
9 """creation of new events""" 10 """creation of new events"""
10 11
11 name = "photos_new" 12 name = "photos_new"
12 access = C.PAGES_ACCESS_PROFILE 13 access = C.PAGES_ACCESS_PROFILE
16 17
17 async def on_data_post(self, request): 18 async def on_data_post(self, request):
18 request_data = self.getRData(request) 19 request_data = self.getRData(request)
19 profile = self.getProfile(request) 20 profile = self.getProfile(request)
20 name = self.getPostedData(request, "name").replace('/', '_') 21 name = self.getPostedData(request, "name").replace('/', '_')
22 albums_path = "/albums"
23 album_path = f"{albums_path}/{name}"
21 if profile is None: 24 if profile is None:
22 self.pageError(request, C.HTTP_BAD_REQUEST) 25 self.pageError(request, C.HTTP_BAD_REQUEST)
23 fis_ns = self.host.ns_map["fis"] 26 fis_ns = self.host.ns_map["fis"]
24 http_upload_ns = self.host.ns_map["http_upload"] 27 http_upload_ns = self.host.ns_map["http_upload"]
25 entities_services, __, __ = await self.host.bridgeCall( 28 entities_services, __, __ = await self.host.bridgeCall(
38 except StopIteration: 41 except StopIteration:
39 raise exceptions.DataError(D_( 42 raise exceptions.DataError(D_(
40 "You server has no service to create a photo album, please ask your server " 43 "You server has no service to create a photo album, please ask your server "
41 "administrator to add one")) 44 "administrator to add one"))
42 45
46 try:
47 await self.host.bridgeCall(
48 "FISCreateDir",
49 fis_service,
50 "",
51 albums_path,
52 {"access_model": "open"},
53 profile
54 )
55 except BridgeException as e:
56 if e.condition == 'conflict':
57 pass
58 else:
59 log.error(f"Can't create {albums_path} path: {e}")
60 raise e
61
62 try:
63 await self.host.bridgeCall(
64 "FISCreateDir",
65 fis_service,
66 "",
67 album_path,
68 {"access_model": "whitelist"},
69 profile
70 )
71 except BridgeException as e:
72 if e.condition == 'conflict':
73 pass
74 else:
75 log.error(f"Can't create {album_path} path: {e}")
76 raise e
77
43 await self.host.bridgeCall( 78 await self.host.bridgeCall(
44 "interestsRegisterFileSharing", 79 "interestsRegisterFileSharing",
45 fis_service, 80 fis_service,
46 "photos", 81 "photos",
47 "", 82 "",
48 f"/albums/{name}", 83 album_path,
49 name, 84 name,
50 "", 85 "",
51 profile 86 profile
52 ) 87 )
53 log.info(f"album {name} created") 88 log.info(f"album {name} created")