示例#1
0
    def remove(self, folder, progress=None, **kwargs):
        """
        Delete a folder recursively.

        :param folder: The folder document to delete.
        :type folder: dict
        :param progress: A progress context to record progress on.
        :type progress: girderformindlogger.utility.progress.ProgressContext or None.
        """
        # Remove the contents underneath this folder recursively.
        from girderformindlogger.models.upload import Upload

        self.clean(folder, progress, **kwargs)

        # Delete pending uploads into this folder
        uploadModel = Upload()
        uploads = uploadModel.find({
            'parentId': folder['_id'],
            'parentType': 'folder'
        })
        for upload in uploads:
            uploadModel.remove(upload, progress=progress, **kwargs)
        uploads.close()

        # Delete this folder
        AccessControlledModel.remove(self, folder, progress=progress, **kwargs)
        if progress:
            progress.update(increment=1, message='Deleted folder %s' %
                            folder['name'])
    def remove(self, invitation, progress=None, **kwargs):
        """
        Delete an invitation.

        :param invitation: The invitation document to delete.
        :type invitation: dict
        """
        # Delete this invitation
        AccessControlledModel.remove(self,
                                     invitation,
                                     progress=progress,
                                     **kwargs)
        if progress:
            progress.update(increment=1, message='Deleted invitation')
示例#3
0
    def remove(self, group, **kwargs):
        """
        Delete a group, and all references to it in the database.

        :param group: The group document to delete.
        :type group: dict
        """
        # Remove references to this group from user group membership lists
        from girderformindlogger.models.user import User
        User().update({'groups': group['_id']},
                      {'$pull': {
                          'groups': group['_id']
                      }})

        # Finally, delete the document itself
        AccessControlledModel.remove(self, group)
示例#4
0
 def save(self, job, *args, **kwargs):
     """
     We extend save so that we can serialize the kwargs before sending them
     to the database. This will allow kwargs with $ and . characters in the
     keys.
     """
     job['kwargs'] = json_util.dumps(job['kwargs'])
     job = AccessControlledModel.save(self, job, *args, **kwargs)
     job['kwargs'] = json_util.loads(job['kwargs'])
     return job
示例#5
0
    def setAccessList(self, doc, access, save=False, recurse=False, user=None,
                      progress=noProgress, setPublic=None, publicFlags=None, force=False):
        """
        Overrides AccessControlledModel.setAccessList to add a recursive
        option. When `recurse=True`, this will set the access list on all
        subfolders to which the given user has ADMIN access level. Any
        subfolders that the given user does not have ADMIN access on will be
        skipped.

        :param doc: The folder to set access settings on.
        :type doc: girderformindlogger.models.folder
        :param access: The access control list.
        :type access: dict
        :param save: Whether the changes should be saved to the database.
        :type save: bool
        :param recurse: Whether this access list should be propagated to all
            subfolders underneath this folder.
        :type recurse: bool
        :param user: The current user (for recursive mode filtering).
        :param progress: Progress context to update.
        :type progress: :py:class:`girderformindlogger.utility.progress.ProgressContext`
        :param setPublic: Pass this if you wish to set the public flag on the
            resources being updated.
        :type setPublic: bool or None
        :param publicFlags: Pass this if you wish to set the public flag list on
            resources being updated.
        :type publicFlags: flag identifier str, or list/set/tuple of them, or None
        :param force: Set this to True to set the flags regardless of the passed in
            user's permissions.
        :type force: bool
        """
        progress.update(increment=1, message='Updating ' + doc['name'])
        if setPublic is not None:
            self.setPublic(doc, setPublic, save=False)

        if publicFlags is not None:
            doc = self.setPublicFlags(doc, publicFlags, user=user, save=False, force=force)

        doc = AccessControlledModel.setAccessList(
            self, doc, access, user=user, save=save, force=force)

        if recurse:
            subfolders = self.findWithPermissions({
                'parentId': doc['_id'],
                'parentCollection': 'folder'
            }, user=user, level=AccessType.ADMIN)

            for folder in subfolders:
                self.setAccessList(
                    folder, access, save=True, recurse=True, user=user,
                    progress=progress, setPublic=setPublic, publicFlags=publicFlags, force=force)

        return doc
示例#6
0
    def setUserAccess(self, doc, user, level, save=False):
        """
        This override is used because we only need to augment the access
        field in the case of WRITE access and above since READ access is
        implied by membership or invitation.
        """
        # save parameter not used?
        if level is not None and level > AccessType.READ:
            doc = AccessControlledModel.setUserAccess(self,
                                                      doc,
                                                      user,
                                                      level,
                                                      save=True)
        else:
            doc = AccessControlledModel.setUserAccess(self,
                                                      doc,
                                                      user,
                                                      level=None,
                                                      save=True)

        return doc
示例#7
0
    def remove(self, protoUser, progress=None, **kwargs):
        """
        Delete a protoUser, and all references to it in the database.

        :param protoUser: The protoUser document to delete.
        :type protoUser: dict
        :param progress: A progress context to record progress on.
        :type progress: girderformindlogger.utility.progress.ProgressContext or None.
        """
        from girderformindlogger.models.folder import Folder
        from girderformindlogger.models.group import Group
        from girderformindlogger.models.token import Token

        # Delete all authentication tokens owned by this user
        # Token().removeWithQuery({'userId': user['_id']})

        # Delete all pending group invites for this user
        # Group().update(
        #     {'requests': user['_id']},
        #     {'$pull': {'requests': user['_id']}}
        # )

        # Delete all of the folders under this user
        # folderModel = Folder()
        # folders = folderModel.find({
        #     'parentId': user['_id'],
        #     'parentCollection': 'user'
        # })
        # for folder in folders:
        #     folderModel.remove(folder, progress=progress, **kwargs)

        # Finally, delete the user document itself
        AccessControlledModel.remove(self, protoUser)
        if progress:
            progress.update(
                increment=1,
                message='Deleted protoUser ' + protoUser['email']
            )
示例#8
0
    def remove(self, collection, progress=None, **kwargs):
        """
        Delete a collection recursively.

        :param collection: The collection document to delete.
        :type collection: dict
        :param progress: A progress context to record progress on.
        :type progress: girderformindlogger.utility.progress.ProgressContext or None.
        """
        from girderformindlogger.models.folder import Folder

        folderModel = Folder()
        folders = folderModel.find({
            'parentId': collection['_id'],
            'parentCollection': 'collection'
        })
        for folder in folders:
            folderModel.remove(folder, progress=progress, **kwargs)

        # Delete this collection
        AccessControlledModel.remove(self, collection)
        if progress:
            progress.update(increment=1,
                            message='Deleted collection ' + collection['name'])