Пример #1
0
 def update(self,
            trans,
            library,
            name=None,
            description=None,
            synopsis=None):
     """
     Update the given library
     """
     changed = False
     if not trans.user_is_admin:
         raise exceptions.ItemAccessibilityException(
             'Only administrators can update libraries.')
     if library.deleted:
         raise exceptions.RequestParameterInvalidException(
             'You cannot modify a deleted library. Undelete it first.')
     if name is not None:
         library.name = name
         changed = True
         #  When library is renamed the root folder has to be renamed too.
         folder_manager = FolderManager()
         folder_manager.update(trans, library.root_folder, name=name)
     if description is not None:
         library.description = description
         changed = True
     if synopsis is not None:
         library.synopsis = synopsis
         changed = True
     if changed:
         trans.sa_session.add(library)
         trans.sa_session.flush()
     return library
Пример #2
0
 def update(self,
            trans,
            library,
            name=None,
            description=None,
            synopsis=None):
     """
     Update the given library
     """
     changed = False
     if not trans.user_is_admin:
         current_user_roles = trans.get_current_user_roles()
         library_modify_roles = self.get_modify_roles(trans, library)
         user_can_modify = any(role in library_modify_roles
                               for role in current_user_roles)
         if not user_can_modify:
             raise exceptions.ItemAccessibilityException(
                 "You don't have permission update libraries.")
     if library.deleted:
         raise exceptions.RequestParameterInvalidException(
             'You cannot modify a deleted library. Undelete it first.')
     if name is not None:
         library.name = name
         changed = True
         #  When library is renamed the root folder has to be renamed too.
         folder_manager = FolderManager()
         folder_manager.update(trans, library.root_folder, name=name)
     if description is not None:
         library.description = description
         changed = True
     if synopsis is not None:
         library.synopsis = synopsis
         changed = True
     if changed:
         trans.sa_session.add(library)
         trans.sa_session.flush()
     return library