Пример #1
0
    def on_post(self, req: falcon.Request, resp: falcon.Response,
                store_id: str, project_id: str):
        def _get_tags():
            result = req.params.get("tags[]", None)
            if isinstance(result, str):
                result = [result]
            return result

        project = {}
        for field in OveProjectMeta.EDITABLE_FIELDS:
            project[field] = req.params.get(field, "")
        project["tags"] = _get_tags()
        project["video_controller"] = to_bool(
            req.params.get("video_controller", False))
        project["html_controller"] = to_bool(
            req.params.get("html_controller", False))

        resp.context = {
            "store_id": store_id,
            "project_id": project_id,
            "project": project
        }
        try:
            resp.context["project"] = self._controller.edit_project(
                store_id=store_id,
                project_id=project_id,
                project_data=project,
                auth_token=auth_token(req))
        except:
            raise
Пример #2
0
def _edit(user: UserAccessMeta, auth: AuthManager, args: Namespace,
          add_user: bool):
    if user:
        value = getattr(args, "admin_access", None)
        if value is not None:
            setattr(user, "admin_access", to_bool(value))

        value = getattr(args, "write_groups", None)
        if value is not None:
            setattr(user, "write_groups", value)

        # make sure that the read groups contain the write groups as well
        value = getattr(args, "read_groups", None)
        value = list(set(value +
                         user.write_groups)) if value is not None else list(
                             set(user.read_groups + user.write_groups))
        setattr(user, "read_groups", value)

        if auth.edit_user(access=user,
                          password=args.password,
                          hashed=False,
                          add=add_user):
            _format_user(auth.get_user(user=args.username), multi=False)
        elif add_user:
            print("[Error] Could not add user")
        else:
            print("[Error] No changes were applied")
    else:
        print("[Error] User not found")
Пример #3
0
 def __init__(self, **kwargs):
     self.id = kwargs.get("id", "") or ""
     self.name = kwargs.get("name", "") or ""
     self.description = kwargs.get("description", "") or ""
     self.authors = kwargs.get("authors", "") or ""
     self.publications = kwargs.get("publications", "") or ""
     self.notes = kwargs.get("notes", "") or ""
     self.thumbnail = kwargs.get("thumbnail", "") or ""
     self.controller = kwargs.get("controller", "") or ""
     self.video_controller = to_bool(
         kwargs.get("video_controller", False) or False)
     self.html_controller = to_bool(
         kwargs.get("html_controller", False) or False)
     self.permissions = kwargs.get("permissions", "") or ""
     self.tags = kwargs.get("tags", []) or []
     self.url = kwargs.get("url", "") or ""
     self.default_mode = kwargs.get("default_mode", "") or ""
     self.versions = kwargs.get("versions", "") or ""
     self.presenter_notes = kwargs.get("presenter_notes", "") or ""
Пример #4
0
 def on_get(self, req: falcon.Request, resp: falcon.Response, store_id: str,
            project_id: str, asset_id: str):
     resp.media = self._controller.list_files(
         store_id=store_id,
         project_id=project_id,
         asset_id=asset_id,
         version=req.params.get("version", None),
         hierarchical=to_bool(req.params.get("hierarchical", False)),
         auth_token=auth_token(req))
     resp.status = falcon.HTTP_200
Пример #5
0
    def on_get(self, req: falcon.Request, resp: falcon.Response,
               store_id: str):
        results_filter = build_meta_filter(req.params, default_filter=None)
        metadata = True if results_filter else to_bool(
            req.params.get("metadata", False))

        resp.media = self._controller.list_projects(
            store_id=store_id,
            metadata=metadata,
            result_filter=results_filter,
            access=getattr(req, "user_access", UserAccessMeta()))
        resp.status = falcon.HTTP_200
Пример #6
0
    def on_post(self, req: falcon.Request, resp: falcon.Response,
                store_id: str, project_id: str, asset_id: str):
        filename = unquote_filename(req.params.get("filename", None))
        create_asset = to_bool(req.params.get("create", "False"))
        update_asset = to_bool(req.params.get("update", "False"))

        try:
            meta = self._controller.get_asset_meta(store_id=store_id,
                                                   project_id=project_id,
                                                   asset_id=asset_id)
            if meta.uploaded and not update_asset:
                raise falcon.HTTPBadRequest(
                    title="Asset exists",
                    description=
                    "This asset already has a file. If you wish to change this file, please update the asset."
                )
        except InvalidAssetError:
            if create_asset:
                meta = self._controller.create_asset(store_id=store_id,
                                                     project_id=project_id,
                                                     meta=OveAssetMeta(
                                                         id=asset_id,
                                                         name=asset_id,
                                                         project=project_id))
            else:
                raise falcon.HTTPBadRequest(
                    title="Asset not found",
                    description="You have not created this asset yet.")

        up_fn = partial(self._controller.upload_asset,
                        store_id=store_id,
                        project_id=project_id,
                        asset_id=asset_id,
                        filename=filename,
                        meta=meta,
                        update=update_asset)
        save_filename(up_fn, req)

        resp.media = {'Asset': asset_id, 'Filename': filename}
        resp.status = falcon.HTTP_200
Пример #7
0
    def on_post(self,
                req: falcon.Request,
                resp: falcon.Response,
                store_id: str,
                project_id: str,
                asset_id: str = None):
        filename = unquote_filename(req.params.get("filename", None))
        create = False
        if asset_id is None:
            asset_id = re.sub("\\W+", '_', filename)
            create = True

        self._controller.upload_asset(store_id=store_id,
                                      project_id=project_id,
                                      asset_id=asset_id,
                                      filename=filename,
                                      stream=req.bounded_stream,
                                      update=to_bool(
                                          req.params.get("update", "True")),
                                      create=create,
                                      auth_token=auth_token(req))
        resp.media = {'Status': 'OK'}
        resp.status = falcon.HTTP_200
Пример #8
0
 def _from_public(doc: Dict) -> UserAccessMeta:
     return UserAccessMeta(user=doc.get("user", None), admin_access=to_bool(doc.get("admin_access", False)),
                           read_groups=doc.get("read_groups", []) or [], write_groups=doc.get("write_groups", []) or [])
Пример #9
0
 def _from_db(doc: Dict) -> UserAccessMeta:
     am = doc.get("am", {}) or {}
     return UserAccessMeta(user=doc.get("user", None), admin_access=to_bool(am.get("admin_access", False)),
                           read_groups=am.get("read_groups", []) or [], write_groups=am.get("write_groups", []) or [])