Skip to content

Commit

Permalink
Merge branch 'main' into classview-reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
jace committed Dec 12, 2023
2 parents fe78ff6 + c3e0dda commit 754d3a2
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 25 deletions.
11 changes: 5 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ repos:
- id: pyupgrade
args: ['--keep-runtime-typing', '--py311-plus']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.6
rev: v0.1.7
hooks:
- id: ruff
args: ['--fix', '--exit-non-zero-on-fix']
Expand Down Expand Up @@ -91,7 +91,7 @@ repos:
- toml
- tomli
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
rev: 5.13.0
hooks:
- id: isort
additional_dependencies:
Expand Down Expand Up @@ -138,7 +138,7 @@ repos:
additional_dependencies:
- tomli
- repo: https://github.com/PyCQA/bandit
rev: 1.7.5
rev: 1.7.6
hooks:
- id: bandit
language_version: python3
Expand Down Expand Up @@ -208,11 +208,10 @@ repos:
- id: forbid-tabs
- id: remove-tabs
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
rev: v4.0.0-alpha.4
hooks:
- id: prettier
args:
['--single-quote', '--trailing-comma', 'es5', '--end-of-line', 'lf']
args: ['--single-quote', '--trailing-comma', 'es5', '--end-of-line', 'lf']
exclude: funnel/templates/js/
- repo: https://github.com/ducminh-phan/reformat-gherkin
rev: v3.0.1
Expand Down
1 change: 1 addition & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module.exports = {
endOfLine: 'lf',
singleQuote: true,
trailingComma: 'es5',
printWidth: 88,
};
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 754d3a2

Please sign in to comment.