Resend workspace invitations to email submitted in new member form.
This commit is contained in:
@@ -54,13 +54,14 @@ class Invitations(object):
|
||||
return invite
|
||||
|
||||
@classmethod
|
||||
def create(cls, inviter, workspace_role):
|
||||
def create(cls, inviter, workspace_role, email):
|
||||
invite = Invitation(
|
||||
workspace_role=workspace_role,
|
||||
inviter=inviter,
|
||||
user=workspace_role.user,
|
||||
status=InvitationStatus.PENDING,
|
||||
expiration_time=Invitations.current_expiration_time(),
|
||||
email=email,
|
||||
)
|
||||
db.session.add(invite)
|
||||
db.session.commit()
|
||||
@@ -120,4 +121,6 @@ class Invitations(object):
|
||||
previous_invitation = Invitations._get(token)
|
||||
Invitations._update_status(previous_invitation, InvitationStatus.REVOKED)
|
||||
|
||||
return Invitations.create(user, previous_invitation.workspace_role)
|
||||
return Invitations.create(
|
||||
user, previous_invitation.workspace_role, previous_invitation.email
|
||||
)
|
||||
|
@@ -42,11 +42,13 @@ class Invitation(Base, TimestampsMixin, AuditableMixin):
|
||||
|
||||
expiration_time = Column(TIMESTAMP(timezone=True))
|
||||
|
||||
token = Column(String(), index=True, default=lambda: secrets.token_urlsafe())
|
||||
token = Column(String, index=True, default=lambda: secrets.token_urlsafe())
|
||||
|
||||
email = Column(String, nullable=False)
|
||||
|
||||
def __repr__(self):
|
||||
return "<Invitation(user='{}', workspace_role='{}', id='{}')>".format(
|
||||
self.user_id, self.workspace_role_id, self.id
|
||||
return "<Invitation(user='{}', workspace_role='{}', id='{}', email='{}')>".format(
|
||||
self.user_id, self.workspace_role_id, self.id, self.email
|
||||
)
|
||||
|
||||
@property
|
||||
@@ -82,10 +84,6 @@ class Invitation(Base, TimestampsMixin, AuditableMixin):
|
||||
if self.workspace_role:
|
||||
return self.workspace_role.workspace
|
||||
|
||||
@property
|
||||
def user_email(self):
|
||||
return self.workspace_role.user.email
|
||||
|
||||
@property
|
||||
def user_name(self):
|
||||
return self.workspace_role.user.full_name
|
||||
|
@@ -262,10 +262,8 @@ def create_member(workspace_id):
|
||||
if form.validate():
|
||||
try:
|
||||
new_member = Workspaces.create_member(user, workspace, form.data)
|
||||
invite = Invitations.create(user, new_member)
|
||||
send_invite_email(
|
||||
g.current_user.full_name, invite.token, form.data["email"]
|
||||
)
|
||||
invite = Invitations.create(user, new_member, form.data["email"])
|
||||
send_invite_email(g.current_user.full_name, invite.token, invite.email)
|
||||
|
||||
return redirect(
|
||||
url_for(
|
||||
@@ -381,7 +379,7 @@ def revoke_invitation(workspace_id, token):
|
||||
@bp.route("/workspaces/<workspace_id>/invitations/<token>/resend", methods=["POST"])
|
||||
def resend_invitation(workspace_id, token):
|
||||
invite = Invitations.resend(g.current_user, workspace_id, token)
|
||||
send_invite_email(g.current_user.full_name, invite.token, invite.user_email)
|
||||
send_invite_email(g.current_user.full_name, invite.token, invite.email)
|
||||
return redirect(
|
||||
url_for(
|
||||
"workspaces.workspace_members",
|
||||
|
Reference in New Issue
Block a user