Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To the account menu, list org accounts that user has membership in #1939

Merged
merged 11 commits into from
Dec 12, 2023
36 changes: 24 additions & 12 deletions funnel/templates/account_menu.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,32 @@
class="header__dropdown__item header__dropdown__item--flex mui--text-dark nounderline mui--text-subhead mui--text-light"><span class="profile-avatar profile-avatar--bigger margin-right">{{ faicon(icon='plus', icon_size='title', baseline=false, css_class="mui--text-light") }}</span>{% trans %}Add username{% endtrans %}</a>
</li>
{%- endif %}
{%- with orgmemlist = current_auth.user.views.recent_organization_memberships() %}
{%- if orgmemlist.recent|length -%}
<li>
<a href="{{ url_for('organizations') }}"
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 %}
<li>
<a href="{{ url_for('organizations') }}"
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>
<a href="{{ org.url_for() }}"
class="header__dropdown__item header__dropdown__item--flex header__dropdown__item--morepadding mui--text-dark nounderline">
<span class="profile-avatar margin-right">
{%- if org.logo_url.url %}
<img src="{{ org.logo_url.resize(img_size.profile_logo_small) }}"
alt="{{ org.title }}"/>
{% else %}
<img src="{{ url_for('static', filename='img/default-profile-logo.png') }}"
alt="{{ org.title }}"/>
{% endif %}
</span>
<span class="mui--text-body2 profile-avatar-title profile-avatar-title--prewrap mui--text-dark">{{ org.title }}</span><span class="chip chip--bg-success margin-left text-bold mui--text-body2">{{ faicon(icon='crown-solid', baseline=true, icon_size='body2', css_class="mui--text-success fa-icon--right-margin") }}{% trans %}Member{% endtrans %}</span>
</a>
</li>
{%- endfor %}
{%- endwith %}
{%- with orgmemlist = current_auth.user.views.recent_organization_memberships() %}
{%- if orgmemlist.recent|length -%}
{%- for orgmem in orgmemlist.recent %}
<li>
<a href="{{ orgmem.account.url_for() }}"
Expand Down Expand Up @@ -81,13 +100,6 @@
<a href="{{ url_for('notification_preferences') }}"
class="header__dropdown__item header__dropdown__item--flex mui--text-subhead mui--text-light nounderline"><span class="profile-avatar profile-avatar--bigger margin-right">{{ faicon(icon='bell', icon_size='subhead', baseline=false, css_class="mui--text-light") }}</span>{% trans %}Notification settings{% endtrans %}</a>
</li>
{%- if not orgmemlist.recent|length -%}
<li>
<a href="{{ url_for('organizations') }}"
class="header__dropdown__item header__dropdown__item--flex mui--text-subhead mui--text-light nounderline"
data-cy="org"><span class="profile-avatar profile-avatar--bigger margin-right">{{ faicon(icon='sitemap', icon_size='subhead', baseline=false, css_class="mui--text-light") }}</span>{% trans %}Organizations{% endtrans %}</a>
</li>
{%- endif %}
{%- endwith %}
<li>
<a href="{{ url_for('saved') }}"
Expand Down
20 changes: 20 additions & 0 deletions funnel/views/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
AuthClient,
LoginSession,
Organization,
Project,
db,
sa,
)
Expand Down Expand Up @@ -173,6 +174,25 @@ def recent_organization_memberships(
)


@Account.views()
def organizations_as_member(
obj: Account, limit: int | None = None, order_by_grant: bool = False
) -> list[RoleAccessProxy]:
"""Return organizations that the user has a membership in"""
vidya-ram marked this conversation as resolved.
Show resolved Hide resolved
featured_accounts = Account.query.filter(
Account.name_in(app.config['FEATURED_ACCOUNTS'])
).all()
org_as_members = []
for org in featured_accounts:
membership_project = org.projects.filter(
Project.boxoffice_data.op('@>')({'has_membership': True})
).first()
print('membership_project', membership_project)
vidya-ram marked this conversation as resolved.
Show resolved Hide resolved
if membership_project and membership_project.current_roles.account_member:
vidya-ram marked this conversation as resolved.
Show resolved Hide resolved
org_as_members.append(org)
return org_as_members


@Account.views('avatar_color_code', cached_property=True)
def avatar_color_code(obj: Account) -> int:
"""Return a colour code for the user's autogenerated avatar image."""
Expand Down