feat: allow users to open edit modal if they are the current user or admin, restrict POWERUSERs to read-only access
This commit is contained in:
@ -51,10 +51,15 @@ const messages = {
|
|||||||
const AvCalendar = ({ publisherId, events, selectedDate, cartEvents, lastPublishedDate }) => {
|
const AvCalendar = ({ publisherId, events, selectedDate, cartEvents, lastPublishedDate }) => {
|
||||||
const [editLockedBefore, setEditLockedBefore] = useState(new Date(lastPublishedDate));
|
const [editLockedBefore, setEditLockedBefore] = useState(new Date(lastPublishedDate));
|
||||||
const [isAdmin, setIsAdmin] = useState(false);
|
const [isAdmin, setIsAdmin] = useState(false);
|
||||||
|
const [isPowerUser, setIsPowerUser] = useState(false);
|
||||||
|
const [currentUserId, setCurrentUserId] = useState(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
setIsAdmin(await ProtectedRoute.IsInRole(UserRole.ADMIN));
|
setIsAdmin(await ProtectedRoute.IsInRole(UserRole.ADMIN));
|
||||||
|
setIsPowerUser(await ProtectedRoute.IsInRole(UserRole.POWERUSER));
|
||||||
|
// Assuming you have a way to get the current user's ID
|
||||||
|
setCurrentUserId(await ProtectedRoute.GetCurrentUserId());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to check admin role:", error);
|
console.error("Failed to check admin role:", error);
|
||||||
}
|
}
|
||||||
@ -257,7 +262,7 @@ const AvCalendar = ({ publisherId, events, selectedDate, cartEvents, lastPublish
|
|||||||
|
|
||||||
if (!start || !end) return;
|
if (!start || !end) return;
|
||||||
//readonly for past dates (ToDo: if not admin)
|
//readonly for past dates (ToDo: if not admin)
|
||||||
if (!isAdmin) {
|
if (!isAdmin && !isCurrentUser) {
|
||||||
if (startdate < new Date() || end < new Date() || startdate > end) return;
|
if (startdate < new Date() || end < new Date() || startdate > end) return;
|
||||||
//or if schedule is published (lastPublishedDate)
|
//or if schedule is published (lastPublishedDate)
|
||||||
if (editLockedBefore && startdate < editLockedBefore) {
|
if (editLockedBefore && startdate < editLockedBefore) {
|
||||||
|
Reference in New Issue
Block a user