Skip to content

Commit

Permalink
Permissions bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
rawcomposition committed Dec 17, 2023
1 parent 1fe4cbf commit 6bd1123
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pages/api/group/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default secureApi(async (req, res, token) => {

const hotspots = await Hotspot.find({ _id: { $in: data.hotspots } }, ["-_id", "stateCode", "countyCode"]);
const allStateCodes: string[] = hotspots.map((hotspot: any) => hotspot.stateCode);
const stateCodes = [...new Set(allStateCodes)];
const stateCodes = [...new Set(allStateCodes)].filter(Boolean);
const countyCodes: string[] = [];

hotspots.forEach((hotspot: any) => {
Expand Down
2 changes: 1 addition & 1 deletion pages/api/group/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default secureApi(async (req, res, token) => {
"lng",
]).lean();
const allStateCodes: string[] = hotspots.map((hotspot: any) => hotspot.stateCode);
const stateCodes = [...new Set(allStateCodes)];
const stateCodes = [...new Set(allStateCodes)].filter(Boolean);
const countyCodes: string[] = [];

hotspots.forEach((hotspot: any) => {
Expand Down
10 changes: 6 additions & 4 deletions pages/group/[locationId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PageHeading from "components/PageHeading";
import DeleteBtn from "components/DeleteBtn";
import Title from "components/Title";
import MapList from "components/MapList";
import { formatMarker, getShortName } from "lib/helpers";
import { formatMarker, getShortName, canEdit as checkCanEdit } from "lib/helpers";
import MapBox from "components/MapBox";
import { useUser } from "providers/user";
import BarChartBtn from "components/BarChartBtn";
Expand Down Expand Up @@ -58,9 +58,11 @@ export default function Group({
useLogPageview({ locationId, stateCode, countyCode, countryCode, entity: "group", isBot });
const [showMore, setShowMore] = React.useState(false);
const { user } = useUser();
const canEditGroup =
user?.role === "admin" ||
stateCodes?.some((it: string) => !!user?.regions?.some((myRegion: string) => it.startsWith(myRegion)));

const canEditGroup = checkCanEdit(
{ uid: "", role: user?.role, regions: user?.regions },
stateCodes?.length ? stateCodes : countryCode
);

const locationIds = hotspots.map((it) => it.locationId);
hotspots.sort((a, b) => (a.species || 0) - (b.species || 0)).reverse();
Expand Down
7 changes: 3 additions & 4 deletions pages/hotspot/[locationId].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import MapList from "components/MapList";
import Feather from "icons/Feather";
import Directions from "icons/Directions";
import ImageIcon from "icons/Image";
import { formatMarker } from "lib/helpers";
import { formatMarker, canEdit as checkCanEdit } from "lib/helpers";
import MapBox from "components/MapBox";
import NearbyHotspots from "components/NearbyHotspots";
import FeaturedImage from "components/FeaturedImage";
Expand Down Expand Up @@ -101,9 +101,8 @@ export default function Hotspot({

const mapImages = [...(images?.filter((item) => item.smUrl && item.isMap) || []), ...groupMaps];

const canEdit =
user?.role === "admin" ||
!!user?.regions?.some((it: string) => countyCode?.startsWith(it) || stateCode?.startsWith(it));
const canEdit = checkCanEdit({ uid: "", role: user?.role, regions: user?.regions }, region.code);
console.log(user?.regions);

const base = region?.portal ? `https://ebird.org/${region?.portal}` : "https://ebird.org";

Expand Down

0 comments on commit 6bd1123

Please sign in to comment.