Skip to content
This repository was archived by the owner on Oct 24, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ python:
- "3.5"
- "3.6"

services:
- docker
- redis-server

before_install:
- docker pull mailhog/mailhog
- docker run -d -p 1025:1025 -p 8025:8025 mailhog/mailhog
install:
- pip install --upgrade pip setuptools
- pip install -e ".[testing]"
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on Debian Stretch (9) with sudo:
sudo apt update
sudo apt install git
sudo apt install python3 python3-venv python3-dev python3-pip
sudo apt install redis-server

### Get the source ###

Expand Down Expand Up @@ -112,10 +113,20 @@ run wsgidav server:

## Run Tests and others checks ##

Before running some functional test related to email, you need a local working *MailHog*
see here : https://github.com/mailhog/MailHog

You can run it this way with docker :

docker pull mailhog/mailhog
docker run -d -p 1025:1025 -p 8025:8025 mailhog/mailhog

Run your project's tests:

pytest

### Lints and others checks ###

Run mypy checks:

mypy --ignore-missing-imports --disallow-untyped-defs tracim
Expand Down
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
# others
'filedepot',
'babel',
# mail-notifier
'mako',
'lxml',
'redis',
'rq',
]

tests_require = [
Expand All @@ -42,6 +47,7 @@
'pytest-cov',
'pep8',
'mypy',
'requests'
]

mysql_require = [
Expand Down
57 changes: 57 additions & 0 deletions tests_configs.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[base_test]
sqlalchemy.url = sqlite:///:memory:
depot_storage_name = test
depot_storage_dir = /tmp/test/depot
user.auth_token.validity = 604800
preview_cache_dir = /tmp/test/preview_cache

[mail_test]
sqlalchemy.url = sqlite:///:memory:
depot_storage_name = test
depot_storage_dir = /tmp/test/depot
user.auth_token.validity = 604800
preview_cache_dir = /tmp/test/preview_cache
email.notification.activated = true
email.notification.from.email = test_user_from+{user_id}@localhost
email.notification.from.default_label = Tracim Notifications
email.notification.reply_to.email = test_user_reply+{content_id}@localhost
email.notification.references.email = test_user_refs+{content_id}@localhost
email.notification.content_update.template.html = %(here)s/tracim/templates/mail/content_update_body_html.mak
email.notification.content_update.template.text = %(here)s/tracim/templates/mail/content_update_body_text.mak
email.notification.created_account.template.html = %(here)s/tracim/templates/mail/created_account_body_html.mak
email.notification.created_account.template.text = %(here)s/tracim/templates/mail/created_account_body_text.mak
# Note: items between { and } are variable names. Do not remove / rename them
email.notification.content_update.subject = [{website_title}] [{workspace_label}] {content_label} ({content_status_label})
email.notification.created_account.subject = [{website_title}] Created account
# processing_mode may be sync or async
email.notification.processing_mode = sync
email.notification.smtp.server = 127.0.0.1
email.notification.smtp.port = 1025
email.notification.smtp.user = test_user
email.notification.smtp.password = just_a_password

[mail_test_async]
sqlalchemy.url = sqlite:///:memory:
depot_storage_name = test
depot_storage_dir = /tmp/test/depot
user.auth_token.validity = 604800
preview_cache_dir = /tmp/test/preview_cache
email.notification.activated = true
email.notification.from.email = test_user_from+{user_id}@localhost
email.notification.from.default_label = Tracim Notifications
email.notification.reply_to.email = test_user_reply+{content_id}@localhost
email.notification.references.email = test_user_refs+{content_id}@localhost
email.notification.content_update.template.html = %(here)s/tracim/templates/mail/content_update_body_html.mak
email.notification.content_update.template.text = %(here)s/tracim/templates/mail/content_update_body_text.mak
email.notification.created_account.template.html = %(here)s/tracim/templates/mail/created_account_body_html.mak
email.notification.created_account.template.text = %(here)s/tracim/templates/mail/created_account_body_text.mak
# Note: items between { and } are variable names. Do not remove / rename them
email.notification.content_update.subject = [{website_title}] [{workspace_label}] {content_label} ({content_status_label})
email.notification.created_account.subject = [{website_title}] Created account
# processing_mode may be sync or async
email.notification.processing_mode = sync
email.processing_mode = async
email.notification.smtp.server = 127.0.0.1
email.notification.smtp.port = 1025
email.notification.smtp.user = test_user
email.notification.smtp.password = just_a_password
27 changes: 21 additions & 6 deletions tracim/command/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#from tracim.lib.daemons import RadicaleDaemon
#from tracim.lib.email import get_email_manager
from tracim.exceptions import AlreadyExistError
from tracim.exceptions import NotificationNotSend
from tracim.exceptions import CommandAbortedError
from tracim.lib.core.group import GroupApi
from tracim.lib.core.user import UserApi
Expand Down Expand Up @@ -106,7 +107,13 @@ def _remove_user_from_named_group(
group.users.remove(user)
self._session.flush()

def _create_user(self, login: str, password: str, **kwargs) -> User:
def _create_user(
self,
login: str,
password: str,
do_notify: bool,
**kwargs
) -> User:
if not password:
if self._password_required():
raise CommandAbortedError(
Expand All @@ -115,18 +122,23 @@ def _create_user(self, login: str, password: str, **kwargs) -> User:
password = ''

try:
user = self._user_api.create_user(email=login)
user.password = password
self._user_api.save(user)
user = self._user_api.create_user(
email=login,
password=password,
do_save=True,
do_notify=do_notify,
)
# TODO - G.M - 04-04-2018 - [Caldav] Check this code
# # We need to enable radicale if it not already done
# daemons = DaemonsManager()
# daemons.run('radicale', RadicaleDaemon)

self._user_api.execute_created_user_actions(user)
except IntegrityError:
self._session.rollback()
raise AlreadyExistError()
except NotificationNotSend as exception:
self._session.rollback()
raise exception

return user

Expand Down Expand Up @@ -166,10 +178,13 @@ def _proceed_user(self, parsed_args: argparse.Namespace) -> User:
try:
user = self._create_user(
login=parsed_args.login,
password=parsed_args.password
password=parsed_args.password,
do_notify=parsed_args.send_email,
)
except AlreadyExistError:
raise CommandAbortedError("Error: User already exist (use `user update` command instead)")
except NotificationNotSend:
raise CommandAbortedError("Error: Cannot send email notification, user not created.")
# TODO - G.M - 04-04-2018 - [Email] Check this code
# if parsed_args.send_email:
# email_manager = get_email_manager()
Expand Down
Loading