def add_member_to_group(group_id): log("Adding member to group...") user_id = request.json.get('user_id') user_email = request.json.get('email') log("Going to check e-mail and user id...") if user_email != "" and user_email is not None and Utils.email_is_valid( user_email): user = User.get_by_email(user_email) if user is not None: log("Email: Adding {} to group {}".format(user_email, group_id)) Group.add_member(group_id, user.id) else: invite = Invite.create(user_email, g.user.id) invite.save() invite.send() else: if user_id != "" and user_id is not None: log("ID: Adding {} to group {}".format(user_id, group_id)) Group.add_member(group_id, user_id) else: response_data = Utils.create_response_error( "InternalServerError", "The server could not fulfil your request", 500) return jsonify(response_data), response_data['status_code'] response_data = Utils.create_response_data( Group.get_by_id(group_id).to_dict(), 200) return jsonify(response_data), response_data['status_code']
def test_activate_email_invite(self): inviter = self._sample_user() invite = Invite.create("*****@*****.**", inviter.id) with self.app_context: invite.save() Invite.activate(invite.token, "pass") user = User.get_by_email(invite.email) self.assertIsNotNone(user) self.assertEqual(user.email, invite.email) User.remove(user.id) Group.remove_member(invite.inviter_id, user.id)