Skip to content
This repository has been archived by the owner on Apr 28, 2020. It is now read-only.

Commit

Permalink
Delete members team
Browse files Browse the repository at this point in the history
The Members team was introduced in #28, but has never gained traction, so is being deleted to aid transition to the direct membership model presented in #151, #118 and #232. The final switch to direct org membership will happen elsewhere, in hasgeek/funnel#401.
  • Loading branch information
jace committed Mar 23, 2020
1 parent 4cbde6d commit 573a7e1
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 41 deletions.
21 changes: 2 additions & 19 deletions lastuser_core/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,14 @@ def organizations_memberof(self):
"""
Return the organizations this user is a member of.
"""
return sorted(
{team.org for team in self.teams if team.org.members == team},
key=lambda o: o.title,
)
return sorted({team.org for team in self.teams}, key=lambda o: o.title)

def organizations_memberof_ids(self):
"""
Return the database ids of the organizations this user is a member of. This is used
for database queries.
"""
return list({team.org.id for team in self.teams if team.org.members == team})
return list({team.org.id for team in self.teams})

def is_profile_complete(self):
"""
Expand Down Expand Up @@ -676,18 +673,6 @@ class Organization(SharedNameMixin, UuidMixin, BaseMixin, db.Model):
cascade='all',
post_update=True,
) # No delete-orphan cascade here
members_id = db.Column(
None,
db.ForeignKey('team.id', use_alter=True, name='organization_members_id_fkey'),
nullable=True,
)
members = db.relationship(
'Team',
primaryjoin='Organization.members_id == Team.id',
uselist=False,
cascade='all',
post_update=True,
) # No delete-orphan cascade here
title = db.Column(db.Unicode(__title_length__), default='', nullable=False)
#: Deprecated, but column preserved for existing data until migration
description = deferred(db.Column(db.UnicodeText, default='', nullable=False))
Expand Down Expand Up @@ -720,8 +705,6 @@ def name(cls): # NOQA: N805
def make_teams(self):
if self.owners is None:
self.owners = Team(title=_("Owners"), org=self)
if self.members is None:
self.members = Team(title=_("Members"), org=self)

def __repr__(self):
return '<Organization {name} "{title}">'.format(
Expand Down
2 changes: 0 additions & 2 deletions lastuser_oauth/views/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def get_userinfo(user, client, scope=[], session=None, get_permissions=True):
'org': team.org.buid,
'org_uuid': team.org.uuid,
'owners': team == team.org.owners,
'members': team == team.org.members,
'member': True,
}

Expand All @@ -122,7 +121,6 @@ def get_userinfo(user, client, scope=[], session=None, get_permissions=True):
'org': team.org.buid,
'org_uuid': team.org.uuid,
'owners': team == team.org.owners,
'members': team == team.org.members,
'member': False,
}

Expand Down
2 changes: 1 addition & 1 deletion lastuser_ui/templates/org_info.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<div class="mui-divider"></div>
<div class="card__footer">
<a href="{{ team.url_for('edit') }}" class="mui-btn mui-btn--small mui-btn--flat mui-btn--primary">Edit</a>
{%- if team != org.owners and team != org.members %}
{%- if team != org.owners %}
<a href="{{ team.url_for('delete') }}" class="mui-btn mui-btn--small mui-btn--flat mui-btn--danger">delete</a>
{%- endif %}
</div>
Expand Down
4 changes: 1 addition & 3 deletions lastuser_ui/views/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def new(self):
form.populate_obj(org)
if current_auth.user not in org.owners.users:
org.owners.users.append(current_auth.user)
if current_auth.user not in org.members.users:
org.members.users.append(current_auth.user)
db.session.add(org)
db.session.commit()
org_data_changed.send(org, changes=['new'], user=current_auth.user)
Expand Down Expand Up @@ -162,7 +160,7 @@ def edit(self):
@route('delete', methods=['GET', 'POST'])
@requires_permission('delete')
def delete(self):
if self.obj == self.obj.org.owners or self.obj == self.obj.org.members:
if self.obj == self.obj.org.owners:
abort(403)
if request.method == 'POST':
team_data_changed.send(self.obj, changes=['delete'], user=current_auth.user)
Expand Down
33 changes: 33 additions & 0 deletions migrations/versions/4279e1e5aec2_remove_members_team.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
"""Remove Members team
Revision ID: 4279e1e5aec2
Revises: 8a9bf9d385c2
Create Date: 2020-03-24 00:24:36.249668
"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = '4279e1e5aec2'
down_revision = '8a9bf9d385c2'
branch_labels = None
depends_on = None


def upgrade():
op.drop_constraint(
'organization_members_id_fkey', 'organization', type_='foreignkey'
)
op.drop_column('organization', 'members_id')


def downgrade():
op.add_column(
'organization',
sa.Column('members_id', sa.INTEGER(), autoincrement=False, nullable=True),
)
op.create_foreign_key(
'organization_members_id_fkey', 'organization', 'team', ['members_id'], ['id']
)
1 change: 0 additions & 1 deletion runtestserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
oakley = User(username="oakley", fullname="Oakley 'huh' Dachshund")
dachsunited = Organization(name="dachsunited", title="Dachs United")
dachsunited.owners.users.append(gustav)
dachsunited.members.users.append(oakley)
dachshundworld = Client(
title="Dachshund World",
org=dachsunited,
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/lastuser_core/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,11 @@ def make_fixtures(self):

batdog = Organization(name='batdog', title='Batdog')
batdog.owners.users.append(crusoe)
batdog.members.users.append(oakley)
db.session.add(batdog)
self.batdog = batdog

specialdachs = Organization(name="specialdachs", title="Special Dachshunds")
specialdachs.owners.users.append(oakley)
specialdachs.members.users.append(piglet)
db.session.add(specialdachs)
self.specialdachs = specialdachs

Expand Down
14 changes: 1 addition & 13 deletions tests/unit/lastuser_core/test_model_client_AuthToken.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ def test_authtoken_all(self):
greyback_token = models.AuthToken(client=client, user=greyback, scope=['id'])
pottermania = models.Organization(name='pottermania', title='Pottermania')
pottermania.owners.users.append(hermione)
pottermania_members = [hermione, alastor, greyback, myrtle]
for member in pottermania_members:
pottermania.members.users.append(member)
db.session.add_all(
[
myrtle,
Expand All @@ -124,21 +121,12 @@ def test_authtoken_all(self):
)
db.session.commit()

# scenario 1 and count == 1
# scenario 1
result1 = models.AuthToken.all(pottermania.owners.users)
self.assertIsInstance(result1, list)
self.assertIsInstance(result1[0], models.AuthToken)
self.assertCountEqual(result1, [herminone_token])

# scenario 1 and count > 1
result2 = models.AuthToken.all(pottermania.members.users)
self.assertIsInstance(result2, list)
for each in result2:
self.assertIsInstance(each, models.AuthToken)
self.assertCountEqual(
result2, [herminone_token, alastor_token, greyback_token, myrtle_token]
)

# Scenario 2: When users passed are not an instance of Query class
lily = models.User(username='lily', fullname='Lily Evans Potter')
cho = models.User(username='cho', fullname='Cho Chang')
Expand Down

0 comments on commit 573a7e1

Please sign in to comment.