Skip to content

Commit

Permalink
Simplify view
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Dec 12, 2023
1 parent 857a380 commit 5710ff6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions funnel/templates/account_menu.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
class="header__dropdown__item header__dropdown__item--flex mui--text-dark nounderline mui--text-subhead mui--text-light"
data-cy="org"><span class="profile-avatar profile-avatar--bigger margin-right">{{ faicon(icon='sitemap', icon_size='title', baseline=false, css_class="mui--text-light") }}</span>{% trans %}Organizations{% endtrans %}</a>
</li>
{%- with accountmemlist = current_auth.user.views.organizations_as_member() %}
{%- for org in accountmemlist %}
{%- with orglist = current_auth.user.views.organizations_as_member %}
{%- for org in orglist %}
<li>
<a href="{{ org.url_for() }}"
class="header__dropdown__item header__dropdown__item--flex header__dropdown__item--morepadding mui--text-dark nounderline">
Expand Down
25 changes: 11 additions & 14 deletions funnel/views/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def organizations_as_admin(
owner: bool = False,
limit: int | None = None,
order_by_grant: bool = False,
) -> list[RoleAccessProxy]:
) -> list[RoleAccessProxy[Account]]:
"""Return organizations that the user is an admin of."""
if owner:
orgmems = obj.active_organization_owner_memberships
Expand All @@ -139,7 +139,7 @@ def organizations_as_admin(
@Account.views()
def organizations_as_owner(
obj: Account, limit: int | None = None, order_by_grant: bool = False
) -> list[RoleAccessProxy]:
) -> list[RoleAccessProxy[Account]]:
"""Return organizations that the user is an owner of."""
return obj.views.organizations_as_admin(
owner=True, limit=limit, order_by_grant=order_by_grant
Expand Down Expand Up @@ -173,19 +173,16 @@ def recent_organization_memberships(
)


@Account.views()
def organizations_as_member(
obj: Account, limit: int | None = None, order_by_grant: bool = False
) -> list[RoleAccessProxy]:
@Account.views(cached_property=True)
def organizations_as_member(obj: Account) -> list[RoleAccessProxy[Account]]:
"""Return organizations that the user has a membership in."""
featured_accounts = Account.query.filter(
Account.name_in(app.config['FEATURED_ACCOUNTS'])
).all()
org_as_members = []
for org in featured_accounts:
if org.current_roles.member:
org_as_members.append(org)
return org_as_members
return [
acc.access_for(actor=obj)
for acc in Account.query.filter(
Account.name_in(app.config['FEATURED_ACCOUNTS'])
).all()
if 'member' in acc.roles_for(obj)
]


@Account.views('avatar_color_code', cached_property=True)
Expand Down

0 comments on commit 5710ff6

Please sign in to comment.