record inviter on invitation
This commit is contained in:
parent
edede87108
commit
6125041a93
@ -0,0 +1,32 @@
|
|||||||
|
"""add inviter relationship to invitation
|
||||||
|
|
||||||
|
Revision ID: 2bec1868a22a
|
||||||
|
Revises: c7feaa7b6b0c
|
||||||
|
Create Date: 2018-10-26 12:45:13.192062
|
||||||
|
|
||||||
|
"""
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import postgresql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision = '2bec1868a22a'
|
||||||
|
down_revision = 'c7feaa7b6b0c'
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.add_column('invitations', sa.Column('inviter_id', postgresql.UUID(as_uuid=True), nullable=True))
|
||||||
|
op.create_index(op.f('ix_invitations_inviter_id'), 'invitations', ['inviter_id'], unique=False)
|
||||||
|
op.create_foreign_key(None, 'invitations', 'users', ['inviter_id'], ['id'])
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade():
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.drop_constraint(None, 'invitations', type_='foreignkey')
|
||||||
|
op.drop_index(op.f('ix_invitations_inviter_id'), table_name='invitations')
|
||||||
|
op.drop_column('invitations', 'inviter_id')
|
||||||
|
# ### end Alembic commands ###
|
@ -30,8 +30,8 @@ class Invitations(object):
|
|||||||
return invite
|
return invite
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create(cls, workspace, user):
|
def create(cls, workspace, inviter, user):
|
||||||
invite = Invitation(workspace=workspace, user=user, valid=True)
|
invite = Invitation(workspace=workspace, inviter=inviter, user=user, valid=True)
|
||||||
db.session.add(invite)
|
db.session.add(invite)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -12,11 +12,14 @@ class Invitation(Base, TimestampsMixin):
|
|||||||
id = types.Id()
|
id = types.Id()
|
||||||
|
|
||||||
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), index=True)
|
user_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), index=True)
|
||||||
user = relationship("User", backref="invitations")
|
user = relationship("User", backref="invitations", foreign_keys=[user_id])
|
||||||
|
|
||||||
workspace_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id"), index=True)
|
workspace_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id"), index=True)
|
||||||
workspace = relationship("Workspace", backref="invitations")
|
workspace = relationship("Workspace", backref="invitations")
|
||||||
|
|
||||||
|
inviter_id = Column(UUID(as_uuid=True), ForeignKey("users.id"), index=True)
|
||||||
|
inviter = relationship("User", backref="sent_invites", foreign_keys=[inviter_id])
|
||||||
|
|
||||||
valid = Column(Boolean, default=True)
|
valid = Column(Boolean, default=True)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -239,7 +239,7 @@ def create_member(workspace_id):
|
|||||||
if form.validate():
|
if form.validate():
|
||||||
try:
|
try:
|
||||||
new_member = Workspaces.create_member(g.current_user, workspace, form.data)
|
new_member = Workspaces.create_member(g.current_user, workspace, form.data)
|
||||||
invite = Invitations.create(workspace, new_member.user)
|
invite = Invitations.create(workspace, g.current_user, new_member.user)
|
||||||
send_invite_email(
|
send_invite_email(
|
||||||
g.current_user.full_name, invite.id, new_member.user.email
|
g.current_user.full_name, invite.id, new_member.user.email
|
||||||
)
|
)
|
||||||
|
@ -9,16 +9,17 @@ from tests.factories import WorkspaceFactory, UserFactory, InvitationFactory
|
|||||||
def test_create_invitation():
|
def test_create_invitation():
|
||||||
workspace = WorkspaceFactory.create()
|
workspace = WorkspaceFactory.create()
|
||||||
user = UserFactory.create()
|
user = UserFactory.create()
|
||||||
invite = Invitations.create(workspace, user)
|
invite = Invitations.create(workspace, workspace.owner, user)
|
||||||
assert invite.user == user
|
assert invite.user == user
|
||||||
assert invite.workspace == workspace
|
assert invite.workspace == workspace
|
||||||
|
assert invite.inviter == workspace.owner
|
||||||
assert invite.valid
|
assert invite.valid
|
||||||
|
|
||||||
|
|
||||||
def test_accept_invitation():
|
def test_accept_invitation():
|
||||||
workspace = WorkspaceFactory.create()
|
workspace = WorkspaceFactory.create()
|
||||||
user = UserFactory.create()
|
user = UserFactory.create()
|
||||||
invite = Invitations.create(workspace, user)
|
invite = Invitations.create(workspace, workspace.owner, user)
|
||||||
assert invite.valid
|
assert invite.valid
|
||||||
accepted_invite = Invitations.accept(invite.id)
|
accepted_invite = Invitations.accept(invite.id)
|
||||||
assert not accepted_invite.valid
|
assert not accepted_invite.valid
|
||||||
|
Loading…
x
Reference in New Issue
Block a user