Example #1
0
    def post(self, body):
        osbrepository = OSBRepository.from_dict(body)  # Validate
        if 'user_id' not in body:
            body['user_id'] = keycloak_user_id()

        self.map_entity(body)
        return super().post(body)
Example #2
0
 def is_authorized(self, workspace):
     current_user_id = keycloak_user_id()
     return workspace and (
         workspace.publicable or
         (workspace.user_id and workspace.user_id == current_user_id) or
         (get_auth_client().user_has_realm_role(user_id=current_user_id,
                                                role="administrator")))
Example #3
0
    def post(self, body):
        if 'user_id' not in body:
            body['user_id'] = keycloak_user_id()
        for r in body.get("resources", []):
            r.update({"origin": json.dumps(r.get("origin"))})
        workspace = Workspace.from_dict(body)  # Validate
        workspace = super().post(body)

        create_volume(name=self.get_pvc_name(workspace.id),
                      size=self.get_workspace_volume_size(workspace))
        return workspace
Example #4
0
    def search(self, page=1, per_page=20, *args, **kwargs) -> Pagination:
        """
        Query the model and return all records

        Args:
            page: The page number
            per_page: The number of records per page to limit

        Returns:
            dict with all records from the model
            current page
            number of pages
        """
        logger.debug("Search args %s", args)
        logger.debug("Search kwargs %s", kwargs)

        current_user_id = keycloak_user_id()

        if current_user_id is not None:
            # Admins see all workspaces, non admin users can see only their own workspaces
            if not get_auth_client().user_has_realm_role(
                    user_id=current_user_id, role="administrator"):
                objects = self.repository.search(page=page,
                                                 per_page=per_page,
                                                 user_id=current_user_id,
                                                 *args,
                                                 **kwargs)
            else:
                objects = self.repository.search(page=page,
                                                 per_page=per_page,
                                                 user_id=current_user_id,
                                                 show_all=True,
                                                 *args,
                                                 **kwargs)
        else:
            objects = self.repository.search(page=page,
                                             per_page=per_page,
                                             *args,
                                             **kwargs)
        for obj in objects.items:
            self._calculated_fields_populate(obj)
        return objects
Example #5
0
    def clone(self, workspace_id):
        from workspaces.service.workflow import clone_workspaces_content
        workspace = self.get(workspace_id)
        if workspace is None:
            raise Exception(
                f"Cannot clone workspace with id {workspace_id}: not found.")

        cloned = dict(name=f"Clone of {workspace['name']}",
                      tags=workspace['tags'],
                      user_id=keycloak_user_id(),
                      description=workspace['description'],
                      publicable=False,
                      featured=False)
        if workspace['thumbnail']:
            cloned['thumbnail'] = workspace['thumbnail']

        cloned = self.repository.post(cloned, do_post=False)

        create_volume(name=self.get_pvc_name(cloned.id),
                      size=self.get_workspace_volume_size(workspace))
        clone_workspaces_content(workspace_id, cloned.id)
        return cloned
Example #6
0
 def is_authorized(self, volume_storage):
     current_user_id = keycloak_user_id()
     return (get_auth_client().user_has_realm_role(user_id=current_user_id,
                                                   role="administrator"))