def create_invited_user(service_id): request_json = request.get_json() invited_user, errors = invited_user_schema.load(request_json) save_invited_user(invited_user) template = dao_get_template_by_id( current_app.config['INVITATION_EMAIL_TEMPLATE_ID']) service = Service.query.get(current_app.config['NOTIFY_SERVICE_ID']) saved_notification = persist_notification( template_id=template.id, template_version=template.version, recipient=invited_user.email_address, service=service, personalisation={ 'user_name': invited_user.from_user.name, 'service_name': invited_user.service.name, 'url': invited_user_url( invited_user.id, request_json.get('invite_link_host'), ), }, notification_type=EMAIL_TYPE, api_key_id=None, key_type=KEY_TYPE_NORMAL, reply_to_text=invited_user.from_user.email_address) send_notification_to_queue(saved_notification, False, queue=QueueNames.NOTIFY) return jsonify(data=invited_user_schema.dump(invited_user).data), 201
def update_invited_user(service_id, invited_user_id): fetched = get_invited_user(service_id=service_id, invited_user_id=invited_user_id) current_data = dict(invited_user_schema.dump(fetched).data.items()) current_data.update(request.get_json()) update_dict = invited_user_schema.load(current_data).data save_invited_user(update_dict) return jsonify(data=invited_user_schema.dump(fetched).data), 200
def test_save_invited_user_sets_status_to_cancelled(notify_db, notify_db_session, sample_invited_user): assert InvitedUser.query.count() == 1 saved = InvitedUser.query.get(sample_invited_user.id) assert saved.status == 'pending' saved.status = 'cancelled' save_invited_user(saved) assert InvitedUser.query.count() == 1 cancelled_invited_user = InvitedUser.query.get(sample_invited_user.id) assert cancelled_invited_user.status == 'cancelled'
def sample_invited_user(notify_db_session): service = create_service(check_if_service_exists=True) to_email_address = '*****@*****.**' from_user = service.users[0] data = { 'service': service, 'email_address': to_email_address, 'from_user': from_user, 'permissions': 'send_messages,manage_service,manage_api_keys', 'folder_permissions': ['folder_1_id', 'folder_2_id'], } invited_user = InvitedUser(**data) save_invited_user(invited_user) return invited_user
def create_invited_user(service=None, to_email_address=None): if service is None: service = create_service() if to_email_address is None: to_email_address = '*****@*****.**' from_user = service.users[0] data = { 'service': service, 'email_address': to_email_address, 'from_user': from_user, 'permissions': 'send_messages,manage_service,manage_api_keys' } invited_user = InvitedUser(**data) save_invited_user(invited_user) return invited_user
def sample_invited_user(notify_db, notify_db_session, service=None, to_email_address=None): if service is None: service = create_service(check_if_service_exists=True) if to_email_address is None: to_email_address = "*****@*****.**" from_user = service.users[0] data = { "service": service, "email_address": to_email_address, "from_user": from_user, "permissions": "send_messages,manage_service,manage_api_keys", "folder_permissions": ["folder_1_id", "folder_2_id"], } invited_user = InvitedUser(**data) save_invited_user(invited_user) return invited_user
def test_create_invited_user_sets_default_folder_permissions_of_empty_list( notify_db, notify_db_session, sample_service, ): assert InvitedUser.query.count() == 0 invite_from = sample_service.users[0] data = { 'service': sample_service, 'email_address': '*****@*****.**', 'from_user': invite_from, 'permissions': 'send_messages,manage_service', } invited_user = InvitedUser(**data) save_invited_user(invited_user) assert InvitedUser.query.count() == 1 assert invited_user.folder_permissions == []
def test_create_invited_user_sets_default_folder_permissions_of_empty_list( notify_db, notify_db_session, sample_service, ): assert InvitedUser.query.count() == 0 invite_from = sample_service.users[0] data = { "service": sample_service, "email_address": "*****@*****.**", "from_user": invite_from, "permissions": "send_messages,manage_service", } invited_user = InvitedUser(**data) save_invited_user(invited_user) assert InvitedUser.query.count() == 1 assert invited_user.folder_permissions == []
def create_invited_user(service=None, to_email_address=None): if service is None: service = create_service() if to_email_address is None: to_email_address = "*****@*****.**" from_user = service.users[0] data = { "service": service, "email_address": to_email_address, "from_user": from_user, "permissions": "send_messages,manage_service,manage_api_keys", "folder_permissions": [str(uuid.uuid4()), str(uuid.uuid4())], } invited_user = InvitedUser(**data) save_invited_user(invited_user) return invited_user
def sample_invited_user(notify_db, notify_db_session, service=None, to_email_address=None): if service is None: service = sample_service(notify_db, notify_db_session) if to_email_address is None: to_email_address = '*****@*****.**' from_user = service.users[0] data = { 'service': service, 'email_address': to_email_address, 'from_user': from_user, 'permissions': 'send_messages,manage_service,manage_api_keys' } invited_user = InvitedUser(**data) save_invited_user(invited_user) return invited_user
def test_create_invited_user(notify_db, notify_db_session, sample_service): assert InvitedUser.query.count() == 0 email_address = '*****@*****.**' invite_from = sample_service.users[0] data = { 'service': sample_service, 'email_address': email_address, 'from_user': invite_from, 'permissions': 'send_messages,manage_service' } invited_user = InvitedUser(**data) save_invited_user(invited_user) assert InvitedUser.query.count() == 1 assert invited_user.email_address == email_address assert invited_user.from_user == invite_from permissions = invited_user.get_permissions() assert len(permissions) == 2 assert 'send_messages' in permissions assert 'manage_service' in permissions
def test_create_invited_user(notify_db, notify_db_session, sample_service): assert InvitedUser.query.count() == 0 email_address = "*****@*****.**" invite_from = sample_service.users[0] data = { "service": sample_service, "email_address": email_address, "from_user": invite_from, "permissions": "send_messages,manage_service", "folder_permissions": [], } invited_user = InvitedUser(**data) save_invited_user(invited_user) assert InvitedUser.query.count() == 1 assert invited_user.email_address == email_address assert invited_user.from_user == invite_from permissions = invited_user.get_permissions() assert len(permissions) == 2 assert "send_messages" in permissions assert "manage_service" in permissions assert invited_user.folder_permissions == []