Add 'enable_new_...' config options. Decent until actual permission system

master
voussoir 2017-03-16 19:54:12 -07:00
parent db628d158e
commit 8692d826c5
3 changed files with 28 additions and 0 deletions

View File

@ -142,6 +142,12 @@ DEFAULT_DATADIR = '.\\_etiquette'
DEFAULT_CONFIGURATION = { DEFAULT_CONFIGURATION = {
'log_level': logging.DEBUG, 'log_level': logging.DEBUG,
'enable_new_album': True,
'enable_new_bookmark': True,
'enable_new_photo': True,
'enable_new_tag': True,
'enable_new_user': True,
'min_tag_name_length': 1, 'min_tag_name_length': 1,
'max_tag_name_length': 32, 'max_tag_name_length': 32,
'valid_tag_chars': string.ascii_lowercase + string.digits + '_', 'valid_tag_chars': string.ascii_lowercase + string.digits + '_',

View File

@ -128,6 +128,13 @@ class WrongLogin(EtiquetteException):
# GENERAL ERRORS # GENERAL ERRORS
@with_error_type
class FeatureDisabled(EtiquetteException):
'''
For when features of the system have been disabled by the configuration.
'''
error_message = 'This feature has been disabled.'
@with_error_type @with_error_type
class NotExclusive(EtiquetteException): class NotExclusive(EtiquetteException):
''' '''

View File

@ -281,6 +281,9 @@ class PDBAlbumMixin:
''' '''
Create a new album. Photos can be added now or later. Create a new album. Photos can be added now or later.
''' '''
if not self.config['enable_new_album']:
raise exceptions.FeatureDisabled('new_album')
albumid = self.generate_id('albums') albumid = self.generate_id('albums')
title = title or '' title = title or ''
description = description or '' description = description or ''
@ -332,6 +335,9 @@ class PDBBookmarkMixin:
yield from self.get_things(thing_type='bookmark') yield from self.get_things(thing_type='bookmark')
def new_bookmark(self, url, title=None, *, author=None, commit=True): def new_bookmark(self, url, title=None, *, author=None, commit=True):
if not self.config['enable_new_bookmark']:
raise exceptions.FeatureDisabled('new_bookmark')
if not url: if not url:
raise ValueError('Must provide a URL') raise ValueError('Must provide a URL')
@ -418,6 +424,9 @@ class PDBPhotoMixin:
Returns the Photo object. Returns the Photo object.
''' '''
if not self.config['enable_new_photo']:
raise exceptions.FeatureDisabled('new_photo')
filename = os.path.abspath(filename) filename = os.path.abspath(filename)
if not os.path.isfile(filename): if not os.path.isfile(filename):
raise FileNotFoundError(filename) raise FileNotFoundError(filename)
@ -907,6 +916,9 @@ class PDBTagMixin:
''' '''
Register a new tag and return the Tag object. Register a new tag and return the Tag object.
''' '''
if not self.config['enable_new_tag']:
raise exceptions.FeatureDisabled('new_tag')
tagname = self.normalize_tagname(tagname) tagname = self.normalize_tagname(tagname)
try: try:
existing_tag = self.get_tag_by_name(tagname) existing_tag = self.get_tag_by_name(tagname)
@ -1022,6 +1034,9 @@ class PDBUserMixin:
return objects.User(self, fetch) return objects.User(self, fetch)
def register_user(self, username, password, commit=True): def register_user(self, username, password, commit=True):
if not self.config['enable_new_user']:
raise exceptions.FeatureDisabled('new_user')
if len(username) < self.config['min_username_length']: if len(username) < self.config['min_username_length']:
raise exceptions.UsernameTooShort( raise exceptions.UsernameTooShort(
username=username, username=username,