Add more feature_required decorators and config.

This commit is contained in:
voussoir 2017-06-14 23:15:47 -07:00
parent 1b9f7608b1
commit 6bed300496
2 changed files with 42 additions and 0 deletions

View file

@ -161,7 +161,9 @@ DEFAULT_CONFIGURATION = {
'enable_new_photo': True,
'enable_new_tag': True,
'enable_new_user': True,
'enable_bookmark_edit': True,
'enable_photo_add_remove_tag': True,
'enable_photo_edit': True,
'enable_photo_generate_thumbnail': True,
'enable_photo_reload_metadata': True,
'enable_tag_edit': True,

View file

@ -241,6 +241,11 @@ class Album(ObjectBase, GroupableMixin):
self._sum_bytes_photos = None
self._sum_bytes_albums = None
@decorators.required_feature('enable_album_edit')
def add(self, *args, **kwargs):
return super().add(*args, **kwargs)
@decorators.required_feature('enable_album_edit')
@decorators.transaction
def add_associated_directory(self, filepath, *, commit=True):
filepath = pathclass.Path(filepath)
@ -272,6 +277,7 @@ class Album(ObjectBase, GroupableMixin):
self.photodb.log.debug('Committing - add associated directory')
self.photodb.commit()
@decorators.required_feature('enable_album_edit')
@decorators.transaction
def add_photo(self, photo, *, commit=True):
if self.photodb != photo.photodb:
@ -286,6 +292,7 @@ class Album(ObjectBase, GroupableMixin):
self.photodb.log.debug('Committing - add photo to album')
self.photodb.commit()
# No required_feature, let the photo.add_tag take care of that.
@decorators.transaction
def add_tag_to_all(self, tag, *, nested_children=True, commit=True):
'''
@ -318,6 +325,7 @@ class Album(ObjectBase, GroupableMixin):
directories = [pathclass.Path(x) for x in directories]
return directories
@decorators.required_feature('enable_album_edit')
@decorators.transaction
def delete(self, *, delete_children=False, commit=True):
self.photodb.log.debug('Deleting album {album:r}'.format(album=self))
@ -370,6 +378,14 @@ class Album(ObjectBase, GroupableMixin):
)
return cur.fetchone() is not None
@decorators.required_feature('enable_album_edit')
def join_group(self, *args, **kwargs):
return super().join_group(*args, **kwargs)
@decorators.required_feature('enable_album_edit')
def leave_group(self, *args, **kwargs):
return super().leave_group(*args, **kwargs)
def photos(self):
photos = []
generator = helpers.select_generator(
@ -384,6 +400,7 @@ class Album(ObjectBase, GroupableMixin):
photos.sort(key=lambda x: x.basename.lower())
return photos
@decorators.required_feature('enable_album_edit')
@decorators.transaction
def remove_photo(self, photo, *, commit=True):
if not self.has_photo(photo):
@ -436,6 +453,7 @@ class Bookmark(ObjectBase):
def __repr__(self):
return 'Bookmark:{id}'.format(id=self.id)
@decorators.required_feature('enable_bookmark_edit')
@decorators.transaction
def delete(self, *, commit=True):
cur = self.photodb.sql.cursor()
@ -443,6 +461,7 @@ class Bookmark(ObjectBase):
if commit:
self.photodb.commit()
@decorators.required_feature('enable_bookmark_edit')
@decorators.transaction
def edit(self, title=None, url=None, *, commit=True):
if title is None and url is None:
@ -575,6 +594,7 @@ class Photo(ObjectBase):
def bytestring(self):
return bytestring.bytestring(self.bytes)
@decorators.required_feature('enable_photo_add_remove_tag')
def copy_tags(self, other_photo):
'''
Take all of the tags owned by other_photo and apply them to this photo.
@ -582,6 +602,7 @@ class Photo(ObjectBase):
for tag in other_photo.tags():
self.add_tag(tag)
@decorators.required_feature('enable_photo_edit')
@decorators.transaction
def delete(self, *, delete_file=False, commit=True):
'''
@ -804,6 +825,7 @@ class Photo(ObjectBase):
self.photodb.log.debug('Committing - reload metadata')
self.photodb.commit()
@decorators.required_feature('enable_photo_edit')
@decorators.transaction
def relocate(self, new_filepath, *, allow_duplicates=False, commit=True):
'''
@ -857,6 +879,7 @@ class Photo(ObjectBase):
self.photodb.log.debug('Committing - remove photo tag')
self.photodb.commit()
@decorators.required_feature('enable_photo_edit')
@decorators.transaction
def rename_file(self, new_filename, *, move=False, commit=True):
'''
@ -979,6 +1002,11 @@ class Tag(ObjectBase, GroupableMixin):
self.photodb.caches['tag'].remove(self.id)
self._cached_qualified_name = None
@decorators.required_feature('enable_tag_edit')
def add(self, *args, **kwargs):
return super().add(*args, **kwargs)
@decorators.required_feature('enable_tag_edit')
@decorators.transaction
def add_synonym(self, synname, *, commit=True):
synname = self.photodb.normalize_tagname(synname)
@ -1004,6 +1032,7 @@ class Tag(ObjectBase, GroupableMixin):
return synname
@decorators.required_feature('enable_tag_edit')
@decorators.transaction
def convert_to_synonym(self, mastertag, *, commit=True):
'''
@ -1053,6 +1082,7 @@ class Tag(ObjectBase, GroupableMixin):
self.photodb.log.debug('Committing - convert to synonym')
self.photodb.commit()
@decorators.required_feature('enable_tag_edit')
@decorators.transaction
def delete(self, *, delete_children=False, commit=True):
self.photodb.log.debug('Deleting tag {tag:r}'.format(tag=self))
@ -1086,6 +1116,14 @@ class Tag(ObjectBase, GroupableMixin):
self.photodb.log.debug('Committing - edit tag')
self.photodb.commit()
@decorators.required_feature('enable_tag_edit')
def join_group(self, *args, **kwargs):
return super().join_group(*args, **kwargs)
@decorators.required_feature('enable_tag_edit')
def leave_group(self, *args, **kwargs):
return super().leave_group(*args, **kwargs)
def qualified_name(self, *, max_len=None):
'''
Return the 'group1.group2.tag' string for this tag.
@ -1121,6 +1159,7 @@ class Tag(ObjectBase, GroupableMixin):
return qualname
@decorators.required_feature('enable_tag_edit')
@decorators.transaction
def remove_synonym(self, synname, *, commit=True):
'''
@ -1147,6 +1186,7 @@ class Tag(ObjectBase, GroupableMixin):
self.photodb.log.debug('Committing - remove synonym')
self.photodb.commit()
@decorators.required_feature('enable_tag_edit')
@decorators.transaction
def rename(self, new_name, *, apply_to_synonyms=True, commit=True):
'''