123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
-
- from urllib.parse import urlparse
-
- import os
- from paste.deploy.converters import asbool
- from tracim_backend.lib.utils.logger import logger
- from depot.manager import DepotManager
- from tracim_backend.models.contents import CONTENT_TYPES
- from tracim_backend.models.data import ActionDescription
-
-
-
- class CFG(object):
- """Object used for easy access to config file parameters."""
-
- def __setattr__(self, key, value):
- """
- Log-ready setter.
-
- Logs all configuration parameters except password.
- :param key:
- :param value:
- :return:
- """
- if 'PASSWORD' not in key and \
- ('URL' not in key or type(value) == str) and \
- 'CONTENT' not in key:
-
-
-
-
- logger.info(self, 'CONFIG: [ {} | {} ]'.format(key, value))
- else:
- logger.info(self, 'CONFIG: [ {} | <value not shown> ]'.format(key))
-
- self.__dict__[key] = value
-
- def __init__(self, settings):
- """Parse configuration file."""
-
-
-
-
-
- mandatory_msg = \
- 'ERROR: {} configuration is mandatory. Set it before continuing.'
- self.DEPOT_STORAGE_DIR = settings.get(
- 'depot_storage_dir',
- )
- if not self.DEPOT_STORAGE_DIR:
- raise Exception(
- mandatory_msg.format('depot_storage_dir')
- )
- self.DEPOT_STORAGE_NAME = settings.get(
- 'depot_storage_name',
- )
- if not self.DEPOT_STORAGE_NAME:
- raise Exception(
- mandatory_msg.format('depot_storage_name')
- )
- self.PREVIEW_CACHE_DIR = settings.get(
- 'preview_cache_dir',
- )
- if not self.PREVIEW_CACHE_DIR:
- raise Exception(
- 'ERROR: preview_cache_dir configuration is mandatory. '
- 'Set it before continuing.'
- )
-
- self.DATA_UPDATE_ALLOWED_DURATION = int(settings.get(
- 'content.update.allowed.duration',
- 0,
- ))
-
- self.WEBSITE_TITLE = settings.get(
- 'website.title',
- 'TRACIM',
- )
-
- self.WEBSITE_BASE_URL = settings.get(
- 'website.base_url',
- '',
- )
- if not self.WEBSITE_BASE_URL:
- raise Exception(
- 'website.base_url is needed in order to have correct path in'
- 'few place like in email.'
- 'You should set it with frontend root url.'
- )
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- self.WEBSITE_SERVER_NAME = settings.get(
- 'website.server_name',
- None,
- )
-
- if not self.WEBSITE_SERVER_NAME:
- self.WEBSITE_SERVER_NAME = urlparse(self.WEBSITE_BASE_URL).hostname
- logger.warning(
- self,
- 'NOTE: Generated website.server_name parameter from '
- 'website.base_url parameter -> {0}'
- .format(self.WEBSITE_SERVER_NAME)
- )
-
- self.WEBSITE_HOME_TAG_LINE = settings.get(
- 'website.home.tag_line',
- '',
- )
- self.WEBSITE_SUBTITLE = settings.get(
- 'website.home.subtitle',
- '',
- )
- self.WEBSITE_HOME_BELOW_LOGIN_FORM = settings.get(
- 'website.home.below_login_form',
- '',
- )
-
- self.WEBSITE_TREEVIEW_CONTENT = settings.get(
- 'website.treeview.content',
- )
-
- self.USER_AUTH_TOKEN_VALIDITY = int(settings.get(
- 'user.auth_token.validity',
- '604800',
- ))
-
- self.DEBUG = asbool(settings.get('debug', False))
-
-
-
-
-
- self.EMAIL_NOTIFICATION_NOTIFIED_EVENTS = [
- ActionDescription.COMMENT,
- ActionDescription.CREATION,
- ActionDescription.EDITION,
- ActionDescription.REVISION,
- ActionDescription.STATUS_UPDATE
- ]
-
- self.EMAIL_NOTIFICATION_NOTIFIED_CONTENTS = [
- CONTENT_TYPES.Page.slug,
- CONTENT_TYPES.Thread.slug,
- CONTENT_TYPES.File.slug,
- CONTENT_TYPES.Comment.slug,
-
- ]
- if settings.get('email.notification.from'):
- raise Exception(
- 'email.notification.from configuration is deprecated. '
- 'Use instead email.notification.from.email and '
- 'email.notification.from.default_label.'
- )
-
- self.EMAIL_NOTIFICATION_FROM_EMAIL = settings.get(
- 'email.notification.from.email',
- 'noreply+{user_id}@trac.im'
- )
- self.EMAIL_NOTIFICATION_FROM_DEFAULT_LABEL = settings.get(
- 'email.notification.from.default_label',
- 'Tracim Notifications'
- )
- self.EMAIL_NOTIFICATION_REPLY_TO_EMAIL = settings.get(
- 'email.notification.reply_to.email',
- )
- self.EMAIL_NOTIFICATION_REFERENCES_EMAIL = settings.get(
- 'email.notification.references.email'
- )
- self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_HTML = settings.get(
- 'email.notification.content_update.template.html',
- )
- self.EMAIL_NOTIFICATION_CONTENT_UPDATE_TEMPLATE_TEXT = settings.get(
- 'email.notification.content_update.template.text',
- )
- self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_HTML = settings.get(
- 'email.notification.created_account.template.html',
- './tracim_backend/templates/mail/created_account_body_html.mak',
- )
- self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_TEMPLATE_TEXT = settings.get(
- 'email.notification.created_account.template.text',
- './tracim_backend/templates/mail/created_account_body_text.mak',
- )
- self.EMAIL_NOTIFICATION_CONTENT_UPDATE_SUBJECT = settings.get(
- 'email.notification.content_update.subject',
- )
- self.EMAIL_NOTIFICATION_CREATED_ACCOUNT_SUBJECT = settings.get(
- 'email.notification.created_account.subject',
- '[{website_title}] Created account',
- )
- self.EMAIL_NOTIFICATION_PROCESSING_MODE = settings.get(
- 'email.notification.processing_mode',
- )
-
- self.EMAIL_NOTIFICATION_ACTIVATED = asbool(settings.get(
- 'email.notification.activated',
- ))
- self.EMAIL_NOTIFICATION_SMTP_SERVER = settings.get(
- 'email.notification.smtp.server',
- )
- self.EMAIL_NOTIFICATION_SMTP_PORT = settings.get(
- 'email.notification.smtp.port',
- )
- self.EMAIL_NOTIFICATION_SMTP_USER = settings.get(
- 'email.notification.smtp.user',
- )
- self.EMAIL_NOTIFICATION_SMTP_PASSWORD = settings.get(
- 'email.notification.smtp.password',
- )
- self.EMAIL_NOTIFICATION_LOG_FILE_PATH = settings.get(
- 'email.notification.log_file_path',
- None,
- )
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- self.EMAIL_PROCESSING_MODE = settings.get(
- 'email.processing_mode',
- 'sync',
- ).upper()
-
- if self.EMAIL_PROCESSING_MODE not in (
- self.CST.ASYNC,
- self.CST.SYNC,
- ):
- raise Exception(
- 'email.processing_mode '
- 'can ''be "{}" or "{}", not "{}"'.format(
- self.CST.ASYNC,
- self.CST.SYNC,
- self.EMAIL_PROCESSING_MODE,
- )
- )
-
- self.EMAIL_SENDER_REDIS_HOST = settings.get(
- 'email.async.redis.host',
- 'localhost',
- )
- self.EMAIL_SENDER_REDIS_PORT = int(settings.get(
- 'email.async.redis.port',
- 6379,
- ))
- self.EMAIL_SENDER_REDIS_DB = int(settings.get(
- 'email.async.redis.db',
- 0,
- ))
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- self.PREVIEW_JPG_RESTRICTED_DIMS = asbool(settings.get(
- 'preview.jpg.restricted_dims', False
- ))
- preview_jpg_allowed_dims_str = settings.get('preview.jpg.allowed_dims', '')
- allowed_dims = []
- if preview_jpg_allowed_dims_str:
- for sizes in preview_jpg_allowed_dims_str.split(','):
- parts = sizes.split('x')
- assert len(parts) == 2
- width, height = parts
- assert width.isdecimal()
- assert height.isdecimal()
- size = PreviewDim(int(width), int(height))
- allowed_dims.append(size)
-
- if not allowed_dims:
- size = PreviewDim(256, 256)
- allowed_dims.append(size)
-
- self.PREVIEW_JPG_ALLOWED_DIMS = allowed_dims
-
- self.FRONTEND_SERVE = asbool(settings.get(
- 'frontend.serve', False
- ))
-
-
-
-
- backend_folder = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
- tracim_v2_folder = os.path.dirname(backend_folder)
- frontend_dist_folder = os.path.join(tracim_v2_folder, 'frontend', 'dist')
-
- self.FRONTEND_DIST_FOLDER_PATH = settings.get(
- 'frontend.dist_folder_path', frontend_dist_folder
- )
-
-
- if self.FRONTEND_SERVE and not os.path.isdir(self.FRONTEND_DIST_FOLDER_PATH):
- raise Exception(
- 'ERROR: {} folder does not exist as folder. '
- 'please set frontend.dist_folder.path'
- 'with a correct value'.format(self.FRONTEND_DIST_FOLDER_PATH)
- )
-
- def configure_filedepot(self):
- depot_storage_name = self.DEPOT_STORAGE_NAME
- depot_storage_path = self.DEPOT_STORAGE_DIR
- depot_storage_settings = {'depot.storage_path': depot_storage_path}
- DepotManager.configure(
- depot_storage_name,
- depot_storage_settings,
- )
-
- class CST(object):
- ASYNC = 'ASYNC'
- SYNC = 'SYNC'
-
- TREEVIEW_FOLDERS = 'folders'
- TREEVIEW_ALL = 'all'
-
-
- class PreviewDim(object):
-
- def __init__(self, width: int, height: int) -> None:
- self.width = width
- self.height = height
-
- def __repr__(self):
- return "<PreviewDim width:{width} height:{height}>".format(
- width=self.width,
- height=self.height,
- )
|