How to use the codalab.objects.permission.check_worksheet_has_all_permission function in codalab

To help you get started, we’ve selected a few codalab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codalab / codalab-worksheets / codalab / client / local_bundle_client.py View on Github external
    @authentication_required
    def add_worksheet_item(self, worksheet_uuid, item):
        """
        Add the given item to the worksheet.
        """
        worksheet = self.model.get_worksheet(worksheet_uuid, fetch_items=False)
        check_worksheet_has_all_permission(self.model, self._current_user(), worksheet)
        worksheet_util.check_worksheet_not_frozen(worksheet)
        self.model.add_worksheet_item(worksheet_uuid, item)
github codalab / codalab-worksheets / codalab / client / local_bundle_client.py View on Github external
    @authentication_required
    def delete_worksheet(self, uuid, force):
        worksheet = self.model.get_worksheet(uuid, fetch_items=True)
        check_worksheet_has_all_permission(self.model, self._current_user(), worksheet)
        if not force:
            if worksheet.frozen:
                raise UsageError("Can't delete worksheet %s because it is frozen (--force to override)." %
                                 worksheet.uuid)
            if len(worksheet.items) > 0:
                raise UsageError("Can't delete worksheet %s because it is not empty (--force to override)." %
                                 worksheet.uuid)
        self.model.delete_worksheet(uuid)
github codalab / codalab-worksheets / codalab / rest / worksheets.py View on Github external
def update_worksheet_metadata(uuid, info):
    """
    Change the metadata of the worksheet |uuid| to |info|,
    where |info| specifies name, title, owner, etc.
    """
    worksheet = local.model.get_worksheet(uuid, fetch_items=False)
    check_worksheet_has_all_permission(local.model, request.user, worksheet)
    metadata = {}
    for key, value in info.items():
        if key == 'name':
            ensure_unused_worksheet_name(value)
        elif key == 'frozen' and value and not worksheet.frozen:
            # ignore the value the client provided, just freeze as long as it's truthy
            value = datetime.datetime.now()
        metadata[key] = value

    local.model.update_worksheet_metadata(worksheet, metadata)
github codalab / codalab-worksheets / codalab / client / local_bundle_client.py View on Github external
    @authentication_required
    def update_worksheet_metadata(self, uuid, info):
        """
        Change the metadata of the worksheet |uuid| to |info|,
        where |info| specifies name, title, owner, etc.
        """
        worksheet = self.model.get_worksheet(uuid, fetch_items=False)
        check_worksheet_has_all_permission(self.model, self._current_user(), worksheet)
        metadata = {}
        for key, value in info.items():
            if key == 'owner_spec':
                metadata['owner_id'] = self._user_spec_to_id(value)
            elif key == 'name':
                self.ensure_unused_worksheet_name(value)
                metadata[key] = value
            elif key == 'title':
                metadata[key] = value
            elif key == 'tags':
                metadata[key] = value
            elif key == 'freeze':
                metadata['frozen'] = datetime.datetime.now()
            else:
                raise UsageError('Unknown key: %s' % key)
        self.model.update_worksheet_metadata(worksheet, metadata)
github codalab / codalab-worksheets / codalab / rest / worksheets.py View on Github external
def set_worksheet_permission(worksheet, group_uuid, permission):
    """
    Give the given |group_uuid| the desired |permission| on |worksheet_uuid|.
    """
    check_worksheet_has_all_permission(local.model, request.user, worksheet)
    local.model.set_group_worksheet_permission(group_uuid, worksheet.uuid, permission)
github codalab / codalab-worksheets / codalab / rest / bundles.py View on Github external
if worksheet_uuid is None:
        abort(
            http.client.BAD_REQUEST,
            "Parent worksheet id must be specified as" "'worksheet' query parameter",
        )

    # Deserialize bundle fields
    bundles = (
        BundleSchema(strict=True, many=True, dump_only=BUNDLE_CREATE_RESTRICTED_FIELDS)
        .load(request.json)
        .data
    )

    # Check for all necessary permissions
    worksheet = local.model.get_worksheet(worksheet_uuid, fetch_items=False)
    check_worksheet_has_all_permission(local.model, request.user, worksheet)
    worksheet_util.check_worksheet_not_frozen(worksheet)
    request.user.check_quota(need_time=True, need_disk=True)

    created_uuids = []
    for bundle in bundles:
        # Prep bundle info for saving into database
        # Unfortunately cannot use the `construct` methods because they don't
        # provide a uniform interface for constructing bundles for all types
        # Hopefully this can all be unified after REST migration is complete
        bundle_uuid = bundle.setdefault('uuid', spec_util.generate_uuid())
        created_uuids.append(bundle_uuid)
        bundle_class = get_bundle_subclass(bundle['bundle_type'])
        bundle['owner_id'] = request.user.user_id
        if issubclass(bundle_class, UploadedBundle) or query_get_bool('wait_for_upload', False):
            bundle['state'] = State.UPLOADING
        else:
github codalab / codalab-worksheets / codalab / rest / worksheets.py View on Github external
def add_worksheet_item(worksheet_uuid, item):
    """
    Add the given item to the worksheet.
    """
    worksheet = local.model.get_worksheet(worksheet_uuid, fetch_items=False)
    check_worksheet_has_all_permission(local.model, request.user, worksheet)
    worksheet_util.check_worksheet_not_frozen(worksheet)
    local.model.add_worksheet_items(worksheet_uuid, [item])