From 66bc146f59453f64d7f002b463bdff0cc19783e3 Mon Sep 17 00:00:00 2001 From: adrian-turjak Date: Wed, 23 Nov 2016 15:16:57 +1300 Subject: [PATCH] user state + signup templates * added new templates for signup * changed task type for openstack SignUp to 'signup' * making the templates change based on the user state (default/existing/disabled) Change-Id: I3d8209fd15425d6f8eefb9c03ad891c26c3b20f8 --- conf/conf.yaml | 12 +++++++++++- stacktask/actions/models.py | 12 ++++++++++++ stacktask/actions/tests.py | 15 ++++++++++----- stacktask/api/v1/openstack.py | 2 ++ .../api/v1/templates/initial_password_token.txt | 2 +- .../api/v1/templates/invite_user_token.txt | 15 +++++++++++---- stacktask/api/v1/templates/signup_completed.txt | 12 ++++++++++++ stacktask/api/v1/templates/signup_initial.txt | 8 ++++++++ stacktask/api/v1/templates/signup_token.txt | 17 +++++++++++++++++ stacktask/test_settings.py | 14 ++++++++++++++ 10 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 stacktask/api/v1/templates/signup_completed.txt create mode 100644 stacktask/api/v1/templates/signup_initial.txt create mode 100644 stacktask/api/v1/templates/signup_token.txt diff --git a/conf/conf.yaml b/conf/conf.yaml index b6ebd0b..6388a45 100644 --- a/conf/conf.yaml +++ b/conf/conf.yaml @@ -125,7 +125,7 @@ DEFAULT_TASK_SETTINGS: # These are cascading overrides for the default settings: TASK_SETTINGS: - create_project: + signup: # You can override 'default_actions' if needed for given taskviews # The order of the actions is order of execution. # @@ -138,6 +138,16 @@ TASK_SETTINGS: - AddDefaultUsersToProjectAction - NewProjectDefaultNetworkAction - SetProjectQuotaAction + emails: + initial: + subject: Your OpenStack signup has been received + template: signup_initial.txt + token: + subject: Your OpenStack signup has been approved + template: signup_token.txt + completed: + subject: Your OpenStack signup has been completed + template: signup_completed.txt notifications: standard: EmailNotification: diff --git a/stacktask/actions/models.py b/stacktask/actions/models.py index c00b1e3..6ee2c90 100644 --- a/stacktask/actions/models.py +++ b/stacktask/actions/models.py @@ -383,6 +383,8 @@ class NewUserAction(UserNameAction, ProjectMixin, UserMixin): user = self._get_target_user() if not user: self.action.need_token = True + # add to cache to use in template + self.action.task.cache['user_state'] = "default" self.set_token_fields(["password"]) self.add_note( 'No user present with username. Need to create new user.') @@ -396,6 +398,8 @@ class NewUserAction(UserNameAction, ProjectMixin, UserMixin): if not user.enabled: self.action.need_token = True self.action.state = "disabled" + # add to cache to use in template + self.action.task.cache['user_state'] = "disabled" # as they are disabled we'll reset their password self.set_token_fields(["password"]) self.add_note( @@ -417,6 +421,8 @@ class NewUserAction(UserNameAction, ProjectMixin, UserMixin): self.action.need_token = True self.set_token_fields(["confirm"]) self.action.state = "existing" + # add to cache to use in template + self.action.task.cache['user_state'] = "existing" self.add_note( 'Existing user with matching email missing roles.') @@ -647,6 +653,8 @@ class NewProjectWithUserAction(UserNameAction, ProjectMixin, UserMixin): user = id_manager.find_user(self.username, self.domain_id) if not user: + # add to cache to use in template + self.action.task.cache['user_state'] = "default" self.action.need_token = True self.set_token_fields(["password"]) self.add_note("No user present with username '%s'." % @@ -660,6 +668,8 @@ class NewProjectWithUserAction(UserNameAction, ProjectMixin, UserMixin): if not user.enabled: self.action.state = "disabled" + # add to cache to use in template + self.action.task.cache['user_state'] = "disabled" self.action.need_token = True self.add_note( "Existing disabled user '%s' with matching email." % @@ -667,6 +677,8 @@ class NewProjectWithUserAction(UserNameAction, ProjectMixin, UserMixin): return True else: self.action.state = "existing" + # add to cache to use in template + self.action.task.cache['user_state'] = "existing" self.action.need_token = False self.add_note("Existing user '%s' with matching email." % self.email) diff --git a/stacktask/actions/tests.py b/stacktask/actions/tests.py index a1ca259..6becd67 100644 --- a/stacktask/actions/tests.py +++ b/stacktask/actions/tests.py @@ -446,7 +446,8 @@ class ActionTests(TestCase): 'test_project') self.assertEquals( task.cache, - {'project_id': 'project_id_1', 'user_id': 'user_id_1'}) + {'project_id': 'project_id_1', 'user_id': 'user_id_1', + 'user_state': 'default'}) token_data = {'password': '123456'} action.submit(token_data) @@ -497,7 +498,8 @@ class ActionTests(TestCase): 'test_project') self.assertEquals( task.cache, - {'project_id': 'project_id_1', 'user_id': 'user_id_1'}) + {'project_id': 'project_id_1', 'user_id': 'user_id_1', + 'user_state': 'default'}) action.post_approve() self.assertEquals(action.valid, True) @@ -506,7 +508,8 @@ class ActionTests(TestCase): 'test_project') self.assertEquals( task.cache, - {'project_id': 'project_id_1', 'user_id': 'user_id_1'}) + {'project_id': 'project_id_1', 'user_id': 'user_id_1', + 'user_state': 'default'}) token_data = {'password': '123456'} action.submit(token_data) @@ -563,7 +566,8 @@ class ActionTests(TestCase): 'test_project') self.assertEquals( task.cache, - {'user_id': 'user_id_1', 'project_id': 'project_id_1'}) + {'user_id': 'user_id_1', 'project_id': 'project_id_1', + 'user_state': 'existing'}) token_data = {'password': '123456'} action.submit(token_data) @@ -621,7 +625,8 @@ class ActionTests(TestCase): 'test_project') self.assertEquals( task.cache, - {'user_id': 'user_id_1', 'project_id': 'project_id_1'}) + {'user_id': 'user_id_1', 'project_id': 'project_id_1', + 'user_state': 'disabled'}) token_data = {'password': '123456'} action.submit(token_data) diff --git a/stacktask/api/v1/openstack.py b/stacktask/api/v1/openstack.py index 792a2eb..fffa0da 100644 --- a/stacktask/api/v1/openstack.py +++ b/stacktask/api/v1/openstack.py @@ -286,6 +286,8 @@ class SignUp(tasks.CreateProject): The openstack endpoint for signups. """ + task_type = "signup" + def get(self, request): """ The SignUp endpoint does not support GET. diff --git a/stacktask/api/v1/templates/initial_password_token.txt b/stacktask/api/v1/templates/initial_password_token.txt index 6777ad8..cbb27eb 100644 --- a/stacktask/api/v1/templates/initial_password_token.txt +++ b/stacktask/api/v1/templates/initial_password_token.txt @@ -9,7 +9,7 @@ This link expires automatically after 24 hours. If expired, you can simply go to Once this is done you will have access to the dashboard and APIs. -You can find examples and documentation on using Openstack at http://www.openstack.org/ +You can find examples and documentation on using Openstack at http://docs.openstack.org/ Kind regards, The Openstack team diff --git a/stacktask/api/v1/templates/invite_user_token.txt b/stacktask/api/v1/templates/invite_user_token.txt index 997c610..56c4eeb 100644 --- a/stacktask/api/v1/templates/invite_user_token.txt +++ b/stacktask/api/v1/templates/invite_user_token.txt @@ -1,10 +1,17 @@ You have been invited by {{ task.keystone_user.username }} to join the project '{{ task.keystone_user.project_name }}' on Openstack. -Please click on this link to accept the invitation: {{ tokenurl }}{{ token }} -New users will be asked to define a password when accepting the invitation. -Existing users will be added to the project and do not need to provide additional information. +Please click on this link to accept the invitation: +{{ tokenurl }}{{ token }} + +{% if task.cache.user_state == "default" %} +You will be asked to define a password when accepting the invitation. After that you will be given access to the project and will be able to login. +{% elif task.cache.user_state == "existing" %} +As an existing user you will be added to the project and do not need to provide additional information. All you have to do is click confirm. +{% elif task.cache.user_state == "disabled" %} +It appears you already have a user account that was disabled. We've reactivated it, but because it may have been a while we've reset your password. After you setup your new password you will be given access to the project and will be able to login. +{% endif %} This link will expire automatically after 24 hours. If expired, you will need to request another one from the person who invited you. Kind regards, -The Openstack team \ No newline at end of file +The Openstack team diff --git a/stacktask/api/v1/templates/signup_completed.txt b/stacktask/api/v1/templates/signup_completed.txt new file mode 100644 index 0000000..187c034 --- /dev/null +++ b/stacktask/api/v1/templates/signup_completed.txt @@ -0,0 +1,12 @@ +{% if task.cache.user_state == "default" %} +This email is to confirm that your Openstack signup has been completed and your new user and password have now been set up. +{% elif task.cache.user_state == "existing" %} +This email is to confirm that your Openstack signup has been completed and your existing user has access to your new project. +{% elif task.cache.user_state == "disabled" %} +This email is to confirm that your Openstack signup has been completed and your existing user has been re-enabled and given access to your new project. +{% endif %} + +If you did not do this yourself, please get in touch with your systems administrator to report suspicious activity and secure your account. + +Kind regards, +The Openstack team \ No newline at end of file diff --git a/stacktask/api/v1/templates/signup_initial.txt b/stacktask/api/v1/templates/signup_initial.txt new file mode 100644 index 0000000..760fa3d --- /dev/null +++ b/stacktask/api/v1/templates/signup_initial.txt @@ -0,0 +1,8 @@ +Hello, + +Your signup is in our system and now waiting approval. + +Once someone has approved it you will be emailed an update. + +Kind regards, +The Openstack team diff --git a/stacktask/api/v1/templates/signup_token.txt b/stacktask/api/v1/templates/signup_token.txt new file mode 100644 index 0000000..11addff --- /dev/null +++ b/stacktask/api/v1/templates/signup_token.txt @@ -0,0 +1,17 @@ +Your OpenStack sign-up has been approved! + +Please follow this link to finalise access to your new OpenStack project: +{{ tokenurl }}{{ token }} + +{% if task.cache.user_state == "default" %} +You will be asked to define a password, after that you will be given access to the project and will be able to login +{% elif task.cache.user_state == "disabled" %} +It appears you already have a user account that was disabled. We've reactivated it, but because it may have been a while we've reset your password. After you setup your new password you will be given access to your new project and will be able to login. +{% endif %} + +This link expires automatically after 24 hours. If expired, you can simply go to the dashboard and request a password reset. + +You can find examples and documentation on using Openstack at http://docs.openstack.org/ + +Kind regards, +The Openstack team diff --git a/stacktask/test_settings.py b/stacktask/test_settings.py index 881a7be..014f129 100644 --- a/stacktask/test_settings.py +++ b/stacktask/test_settings.py @@ -123,6 +123,20 @@ TASK_SETTINGS = { } }, 'create_project': { + 'emails': { + 'initial': { + 'template': 'signup_initial.txt', + 'subject': 'signup received' + }, + 'token': { + 'template': 'signup_token.txt', + 'subject': 'signup approved' + }, + 'completed': { + 'template': 'signup_completed.txt', + 'subject': 'signup completed' + } + }, 'additional_actions': [ 'AddDefaultUsersToProjectAction', 'NewProjectDefaultNetworkAction'