Skip to content

Commit

Permalink
Merge branch 'main' into task-963-create-endpoints-to-handle-org-members
Browse files Browse the repository at this point in the history
  • Loading branch information
rajpatel24 committed Nov 14, 2024
2 parents 3c174df + 878f80f commit f432404
Show file tree
Hide file tree
Showing 136 changed files with 4,292 additions and 1,281 deletions.
43 changes: 41 additions & 2 deletions hub/admin/extend_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from kobo.apps.trash_bin.models.account import AccountTrash
from kobo.apps.trash_bin.utils import move_to_trash
from kpi.models.asset import AssetDeploymentStatus

from .filters import UserAdvancedSearchFilter
from .mixins import AdvancedSearchMixin

Expand Down Expand Up @@ -87,8 +88,10 @@ class OrgInline(admin.StackedInline):
'organization',
'is_admin',
]
can_delete = False
# Override H2 style to make inline section like other fieldsets
classes = ('no-upper',)
raw_id_fields = ('user', 'organization')
readonly_fields = settings.STRIPE_ENABLED and ('active_subscription_status',) or []

def active_subscription_status(self, obj):
if settings.STRIPE_ENABLED:
Expand All @@ -98,6 +101,12 @@ def active_subscription_status(self, obj):
else 'None'
)

def get_readonly_fields(self, request, obj=None):
readonly_fields = ['organization', 'is_admin']
if settings.STRIPE_ENABLED:
readonly_fields.append('active_subscription_status')
return readonly_fields

def has_add_permission(self, request, obj=OrganizationUser):
return False

Expand Down Expand Up @@ -158,6 +167,9 @@ class ExtendedUserAdmin(AdvancedSearchMixin, UserAdmin):
)
actions = ['remove', 'delete']

class Media:
css = {'all': ('admin/css/inline_as_fieldset.css',)}

@admin.action(description='Remove selected users (delete everything but their username)')
def remove(self, request, queryset, **kwargs):
"""
Expand Down Expand Up @@ -235,8 +247,9 @@ def get_queryset(self, request):
)

def get_search_results(self, request, queryset, search_term):

if request.path != '/admin/auth/user/':
queryset = self._filter_queryset(request, queryset)

# If search comes from autocomplete field, use parent class method
return super(UserAdmin, self).get_search_results(
request, queryset, search_term
Expand All @@ -261,6 +274,32 @@ def monthly_submission_count(self, obj):
).aggregate(counter=Sum('counter'))
return instances.get('counter')

def _filter_queryset(self, request, queryset):
auto_complete = request.path == '/admin/autocomplete/'
app_label = request.GET.get('app_label')
model_name = request.GET.get('model_name')

if (
auto_complete
and app_label == 'organizations'
and model_name == 'organizationuser'
):
return self._filter_queryset_for_organization_user(queryset)

return queryset

def _filter_queryset_for_organization_user(self, queryset):
"""
Displays only users whose organization has a single member.
"""
return (
queryset.annotate(
user_count=Count('organizations_organization__organization_users')
)
.filter(user_count__lte=1)
.order_by('username')
)

def _remove_or_delete(
self,
request,
Expand Down
3 changes: 3 additions & 0 deletions hub/static/admin/css/inline_as_fieldset.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.no-upper h2 {
text-transform: unset;
}
18 changes: 6 additions & 12 deletions jsapp/js/account/accountSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ function AccountSidebar() {
setShowPlans(true);
}, [subscriptionStore.isInitialised]);

const showAddOnsLink = useMemo(() => {
return !subscriptionStore.planResponse.length;
}, [subscriptionStore.isInitialised]);

return (
<nav className={styles.accountSidebar}>
<AccountNavLink
Expand All @@ -78,14 +74,12 @@ function AccountSidebar() {
name={t('Plans')}
to={ACCOUNT_ROUTES.PLAN}
/>
{showAddOnsLink && (
<AccountNavLink
iconName='plus'
name={t('Add-ons')}
to={ACCOUNT_ROUTES.ADD_ONS}
isNew
/>
)}
<AccountNavLink
iconName='plus'
name={t('Add-ons')}
to={ACCOUNT_ROUTES.ADD_ONS}
isNew
/>
</>
)}
</>
Expand Down
Loading

0 comments on commit f432404

Please sign in to comment.