Skip to content

Commit

Permalink
To the account menu, list org accounts that user has membership in (#…
Browse files Browse the repository at this point in the history
…1939)

* To the account menu, list org accounts that user has memberhsip in

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Check for org.current_roles.member

* Merge branch 'account-menu-membership' of https://github.com/hasgeek/funnel into account-menu-membership

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add membership badge to profile card

* Update to get user access

* Simplify view

* Specify datasets

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Kiran Jonnalagadda <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent 89f2645 commit f004983
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 19 deletions.
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 orglist = current_auth.user.views.organizations_as_member %}
{%- for org in orglist %}
<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
6 changes: 5 additions & 1 deletion funnel/templates/index.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@
<ul class="grid projects flex-wrapper flex-wrapper--nowrap" role="list">
{% for account in featured_accounts %}
<li class="grid__col-12 grid-no-right-padding" role="listitem">
{{ profilecard(account) }}
{%- if account.current_roles.member %}
{{ profilecard(account, snippet_html=false, is_member=true) }}
{%- else %}
{{ profilecard(account) }}
{% endif %}
</li>
{%- endfor -%}
</ul>
Expand Down
5 changes: 4 additions & 1 deletion funnel/templates/macros.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@
{%- endif %}
{%- endmacro %}

{% macro profilecard(account, snippet_html) %}
{% macro profilecard(account, snippet_html, is_member) %}
<div class="card profile-card">
<div class="card__body">
<div>
Expand All @@ -465,6 +465,9 @@
{%- if snippet_html %}
<p class="mui--text-body2 mui--text-light zero-top-margin search-snippets">{{ faicon(icon='search', css_class="search-icon", baseline=false) }} {{ snippet_html }}</p>
{% endif %}
{%- if is_member %}
<div class="mui--text-dark mui--text-subhead text-bold nounderline margin-auto"><span class="chip chip--bg-success text-bold">{{ faicon(icon='crown-solid', baseline=true, css_class="mui--text-success fa-icon--right-margin") }}{% trans %}Member{% endtrans %}</span></div>
{% endif %}
<div class="profile-card__btn-wrapper">
<p class=" mui--text-center mui--text-caption mui--text-light top-padding margin-bottom">{% trans tcount=account.published_project_count, count=account.published_project_count|numberformat %}One project{% pluralize tcount %}{{ count }} projects{% endtrans %}</p>
<a class="mui-btn mui-btn--primary mui-btn--raised full-width-btn" href="{{ account.url_for() }} ">{% trans %}Explore{% endtrans %}</a>
Expand Down
4 changes: 2 additions & 2 deletions funnel/templates/project_layout.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

{% macro project_header(project) %}
{%- if project.livestream_urls %}
{% if (project.is_restricted_video and project.current_roles.participant) or not project.is_restricted_video %}
{% if (project.is_restricted_video and project.current_roles.account_member) or not project.is_restricted_video %}
<div class="livestream-box project-banner__left" id="livestream">
{% if project.livestream_urls|length >= 2 %}
<ul class="mui-tabs__bar project-banner__box" role="tablist">
Expand Down Expand Up @@ -125,7 +125,7 @@
</a>
{% endif %}
<a href="{{ project.account.url_for() }}" class="mui--text-dark mui--text-subhead text-bold nounderline project-banner__profile-details__text" data-cy="profile-link">{{ project.account.title }}</a>
{% if project.features.subscription and project.current_roles.participant %}
{% if project.features.subscription and project.current_roles.account_member %}
<span class="chip chip--bg-success project-banner__profile-details__badge text-bold">{{ faicon(icon='crown-solid', baseline=true, css_class="mui--text-success fa-icon--right-margin") }}{% trans %}Member{% endtrans %}</span>
{% elif project.features.subscription %}
<span class="chip project-banner__profile-details__badge text-bold">{{ faicon(icon='lock-alt', baseline=true, css_class="fa-icon--right-margin") }}{% trans %}For members{% endtrans %}</span>
Expand Down
16 changes: 14 additions & 2 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,6 +173,18 @@ def recent_organization_memberships(
)


@Account.views(cached_property=True)
def organizations_as_member(obj: Account) -> list[RoleAccessProxy[Account]]:
"""Return organizations that the user has a membership in."""
return [
acc.access_for(actor=obj, datasets=('primary', 'related'))
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)
def avatar_color_code(obj: Account) -> int:
"""Return a colour code for the user's autogenerated avatar image."""
Expand Down
2 changes: 1 addition & 1 deletion funnel/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def home(self) -> ReturnRenderWith:
'featured_project_sessions': scheduled_sessions_list,
'featured_project_schedule': featured_project_schedule,
'featured_accounts': [
p.access_for(roles={'all'}, datasets=('primary', 'related'))
p.current_access(datasets=('primary', 'related'))
for p in featured_accounts
],
}
Expand Down

0 comments on commit f004983

Please sign in to comment.