Skip to content

Commit

Permalink
Manage admins site icon and better view/serializer names (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel-Therrien-Beslogic authored Nov 26, 2024
1 parent 5b0bc8d commit ab4875b
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 199 deletions.
10 changes: 5 additions & 5 deletions canopeum_backend/canopeum_backend/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,23 +300,23 @@ class Meta:
fields = ("is_public",)


class SiteNameSerializer(serializers.ModelSerializer[Site]):
class SiteAdminSiteInfoSerializer(serializers.ModelSerializer[Site]):
class Meta:
model = Site
fields = ("id", "name")
fields = ("id", "name", "site_type")


class AdminUserSitesSerializer(serializers.ModelSerializer[User]):
class SiteAdminsSerializer(serializers.ModelSerializer[User]):
sites = serializers.SerializerMethodField()

class Meta:
model = User
fields = ("id", "username", "email", "sites")

@extend_schema_field(SiteNameSerializer(many=True))
@extend_schema_field(SiteAdminSiteInfoSerializer(many=True))
def get_sites(self, obj):
sites_list = [siteadmin.site for siteadmin in obj.siteadmin_set.all()]
return SiteNameSerializer(sites_list, many=True).data
return SiteAdminSiteInfoSerializer(sites_list, many=True).data


class BatchSponsorSerializer(serializers.ModelSerializer[BatchSponsor]):
Expand Down
4 changes: 2 additions & 2 deletions canopeum_backend/canopeum_backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@
),
# Site admins
path(
"admin-user-sites/",
views.AdminUserSitesAPIView.as_view(),
"site-admins/",
views.SiteAdminsAPIView.as_view(),
name="site_admin-list",
),
# SWAGGER
Expand Down
10 changes: 5 additions & 5 deletions canopeum_backend/canopeum_backend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
Widget,
)
from .serializers import (
AdminUserSitesSerializer,
AnnouncementSerializer,
AssetSerializer,
BatchDetailSerializer,
Expand All @@ -83,6 +82,7 @@
PostSerializer,
RegisterUserSerializer,
SiteAdminSerializer,
SiteAdminsSerializer,
SiteAdminUpdateRequestSerializer,
SiteMapSerializer,
SitePostSerializer,
Expand Down Expand Up @@ -528,18 +528,18 @@ def get(self, request: Request, siteId):
return Response(is_following, status=status.HTTP_200_OK)


class AdminUserSitesAPIView(APIView):
class SiteAdminsAPIView(APIView):
permission_classes = (MegaAdminPermission,)

@extend_schema(
responses=AdminUserSitesSerializer(many=True),
operation_id="admin-user-sites_all",
responses=SiteAdminsSerializer(many=True),
operation_id="site-admins_all",
)
def get(self, request: Request):
forest_stewards = User.objects.filter(role__name__iexact=RoleName.ForestSteward).order_by(
"username"
)
serializer = AdminUserSitesSerializer(forest_stewards, many=True)
serializer = SiteAdminsSerializer(forest_stewards, many=True)
return Response(serializer.data)


Expand Down
16 changes: 6 additions & 10 deletions canopeum_frontend/src/components/settings/AdminCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { AdminUserSites } from '@services/api'
import { getSiteTypeIconKey } from '@models/SiteType'
import type { SiteAdmins } from '@services/api'

type Props = {
readonly admin: AdminUserSites,
readonly admin: SiteAdmins,
}

const AdminCard = ({ admin }: Props) => (
Expand All @@ -19,14 +20,9 @@ const AdminCard = ({ admin }: Props) => (
<div className='card-text mt-3 d-flex flex-column gap-1'>
{admin.sites.map(site => (
<div className='d-flex align-items-center text-primary' key={site.id}>
{
//
/* See TODO
<span className='material-symbols-outlined'>
{getSiteTypeIconKey(site.siteType.id)}
</span> */
}
(TODO: Add site icon here)
<span className='material-symbols-outlined'>
{getSiteTypeIconKey(site.siteType ?? 0)}
</span>
<span className='ms-1'>{site.name}</span>
</div>
))}
Expand Down
4 changes: 2 additions & 2 deletions canopeum_frontend/src/components/settings/ManageAdmins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import AdminCard from '@components/settings/AdminCard'
import AdminInvitationDialog from '@components/settings/AdminInvitationDialog'
import useApiClient from '@hooks/ApiClientHook'
import LoadingPage from '@pages/LoadingPage'
import type { AdminUserSites } from '@services/api'
import type { SiteAdmins } from '@services/api'

const ManageAdmins = () => {
const { t: translate } = useTranslation()
const { getApiClient } = useApiClient()

const [isLoadingAdmins, setIsLoadingAdmins] = useState(true)
const [siteAdminList, setSiteAdminList] = useState<AdminUserSites[]>([])
const [siteAdminList, setSiteAdminList] = useState<SiteAdmins[]>([])
const [showAdminInviteDialog, setShowAdminInviteDialog] = useState(false)

const fetchSiteAdmins = useCallback(async () => {
Expand Down
4 changes: 2 additions & 2 deletions canopeum_frontend/src/hooks/ApiClientHook.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback } from 'react'

import useHttp from './HttpHook'
import { AdminUserSitesClient, AnnouncementClient, AuthenticationClient, BatchClient, CommentClient, ContactClient, FertilizerClient, LikeClient, MulchLayerClient, PostClient, RefreshClient, SiteClient, SocialClient, SummaryClient, TokenClient, TreeClient, UserClient, UserInvitationClient, WidgetClient } from '@services/api'
import { AnnouncementClient, AuthenticationClient, BatchClient, CommentClient, ContactClient, FertilizerClient, LikeClient, MulchLayerClient, PostClient, RefreshClient, SiteAdminsClient, SiteClient, SocialClient, SummaryClient, TokenClient, TreeClient, UserClient, UserInvitationClient, WidgetClient } from '@services/api'
import { getApiBaseUrl } from '@services/apiSettings'

const useApiClient = () => {
Expand All @@ -19,7 +19,7 @@ const useApiClient = () => {
userClient: new UserClient(getApiBaseUrl(), { fetch: fetchWithAuth }),
siteClient: new SiteClient(getApiBaseUrl(), { fetch: fetchWithAuth }),
userInvitationClient: new UserInvitationClient(getApiBaseUrl(), { fetch: fetchWithAuth }),
adminUserSitesClient: new AdminUserSitesClient(getApiBaseUrl(), { fetch: fetchWithAuth }),
adminUserSitesClient: new SiteAdminsClient(getApiBaseUrl(), { fetch: fetchWithAuth }),
summaryClient: new SummaryClient(getApiBaseUrl(), { fetch: fetchWithAuth }),
announcementClient: new AnnouncementClient(getApiBaseUrl(), { fetch: fetchWithAuth }),
contactClient: new ContactClient(getApiBaseUrl(), { fetch: fetchWithAuth }),
Expand Down
Loading

0 comments on commit ab4875b

Please sign in to comment.