mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
fixes after merge
This commit is contained in:
parent
ba0c501d4c
commit
2c6564ecf7
@ -1,22 +1,20 @@
|
|||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import { useLayers } from '../hooks/useLayers'
|
import { useLayers } from '../hooks/useLayers'
|
||||||
import { useHasUserPermission } from '../hooks/usePermissions';
|
import { useHasUserPermission } from '../hooks/usePermissions'
|
||||||
|
|
||||||
|
|
||||||
export default function AddButton ({ triggerAction }: { triggerAction: React.Dispatch<React.SetStateAction<any>> }) {
|
export default function AddButton ({ triggerAction }: { triggerAction: React.Dispatch<React.SetStateAction<any>> }) {
|
||||||
|
const layers = useLayers()
|
||||||
const layers = useLayers();
|
const hasUserPermission = useHasUserPermission()
|
||||||
const hasUserPermission = useHasUserPermission();
|
|
||||||
|
|
||||||
const canAddItems = () => {
|
const canAddItems = () => {
|
||||||
let canAdd = false;
|
let canAdd = false
|
||||||
layers.map(layer => {
|
layers.map(layer => {
|
||||||
if (layer.api?.createItem && hasUserPermission(layer.api.collectionName!, "create", undefined, layer) && layer.listed) canAdd = true;
|
if (layer.api?.createItem && hasUserPermission(layer.api.collectionName!, 'create', undefined, layer) && layer.listed) canAdd = true
|
||||||
|
return null
|
||||||
})
|
})
|
||||||
return canAdd;
|
return canAdd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>{
|
<>{
|
||||||
canAddItems()
|
canAddItems()
|
||||||
|
|||||||
@ -76,15 +76,10 @@ function usePermissionsManager (initialPermissions: Permission[]): {
|
|||||||
item?: Item,
|
item?: Item,
|
||||||
layer?: LayerProps
|
layer?: LayerProps
|
||||||
) => {
|
) => {
|
||||||
|
console.log(layer?.name)
|
||||||
console.log(layer?.name);
|
console.log(user?.role.name)
|
||||||
console.log(user?.role.name);
|
console.log(action)
|
||||||
console.log(action);
|
console.log(permissions.filter(p => p.policy.name === user?.role.name || (p.policy.name === '$t:public_label' && !user)))
|
||||||
console.log(permissions.filter(p => p.policy.name === user?.role.name || (p.policy.name === "$t:public_label" && !user)));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const evaluateCondition = (condition: any) => {
|
const evaluateCondition = (condition: any) => {
|
||||||
if (condition.user_created?._eq === '$CURRENT_USER') {
|
if (condition.user_created?._eq === '$CURRENT_USER') {
|
||||||
@ -105,34 +100,32 @@ function usePermissionsManager (initialPermissions: Permission[]): {
|
|||||||
andCondition._or
|
andCondition._or
|
||||||
? andCondition._or.some((orCondition: any) => evaluateCondition(orCondition))
|
? andCondition._or.some((orCondition: any) => evaluateCondition(orCondition))
|
||||||
: evaluateCondition(andCondition)
|
: evaluateCondition(andCondition)
|
||||||
);
|
)
|
||||||
};
|
}
|
||||||
if (collectionName === "items" && action === "create" && layer?.public_edit_items) return true;
|
if (collectionName === 'items' && action === 'create' && layer?.public_edit_items) return true
|
||||||
// Bedingung für leere Berechtigungen nur, wenn NICHT item und create
|
// Bedingung für leere Berechtigungen nur, wenn NICHT item und create
|
||||||
if (permissions.length === 0) return true;
|
if (permissions.length === 0) return true
|
||||||
else if (user && user.role.id === adminRole) return true;
|
else if (user && user.role.id === adminRole) return true
|
||||||
else {
|
else {
|
||||||
return permissions.some(p =>
|
return permissions.some(p =>
|
||||||
p.action === action &&
|
p.action === action &&
|
||||||
p.collection === collectionName &&
|
p.collection === collectionName &&
|
||||||
|
|
||||||
(
|
(
|
||||||
(p.policy.name === user?.role.name &&
|
(p.policy.name === user?.role.name &&
|
||||||
(
|
(
|
||||||
!item || evaluatePermissions(p.permissions)
|
!item || evaluatePermissions(p.permissions)
|
||||||
)) ||
|
)) ||
|
||||||
(p.policy === "$t:public_label" &&
|
(p.policy === '$t:public_label' &&
|
||||||
(
|
(
|
||||||
(layer?.public_edit_items || item?.layer?.public_edit_items) &&
|
(layer?.public_edit_items || item?.layer?.public_edit_items) &&
|
||||||
(!item || evaluatePermissions(p.permissions))
|
(!item || evaluatePermissions(p.permissions))
|
||||||
))
|
))
|
||||||
)
|
)
|
||||||
|
)
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[permissions, user, adminRole]
|
[permissions, user, adminRole]
|
||||||
);
|
)
|
||||||
|
|
||||||
return { permissions, setPermissionApi, setPermissionData, setAdminRole, hasUserPermission }
|
return { permissions, setPermissionApi, setPermissionData, setAdminRole, hasUserPermission }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,7 +24,7 @@ export function ProfileView ({ userType, attestationApi }: { userType: string, a
|
|||||||
const [offers, setOffers] = useState<Array<Tag>>([])
|
const [offers, setOffers] = useState<Array<Tag>>([])
|
||||||
const [needs, setNeeds] = useState<Array<Tag>>([])
|
const [needs, setNeeds] = useState<Array<Tag>>([])
|
||||||
const [loading, setLoading] = useState<boolean>(false)
|
const [loading, setLoading] = useState<boolean>(false)
|
||||||
const [template, setTemplate] = useState<string>('')
|
const [template/* , setTemplate */] = useState<string>('')
|
||||||
|
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const items = useItems()
|
const items = useItems()
|
||||||
@ -151,7 +151,7 @@ export function ProfileView ({ userType, attestationApi }: { userType: string, a
|
|||||||
<SimpleView item={item}/>
|
<SimpleView item={item}/>
|
||||||
}
|
}
|
||||||
|
|
||||||
{template == "tabs" &&
|
{template === 'tabs' &&
|
||||||
<TabsView userType={userType} attestations={attestations} item={item} loading={loading} offers={offers} needs={needs} relations={relations} updatePermission={updatePermission} linkItem={(id) => linkItem(id, item, updateItem)} unlinkItem={(id) => unlinkItem(id, item, updateItem)}/>
|
<TabsView userType={userType} attestations={attestations} item={item} loading={loading} offers={offers} needs={needs} relations={relations} updatePermission={updatePermission} linkItem={(id) => linkItem(id, item, updateItem)} unlinkItem={(id) => unlinkItem(id, item, updateItem)}/>
|
||||||
}
|
}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@ -12,6 +12,9 @@ import { timeAgo } from '../../../Utils/TimeAgo'
|
|||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
export const TabsView = ({ attestations, userType, item, offers, needs, relations, updatePermission, loading, linkItem, unlinkItem }: { attestations: Array<any>, userType: string, item: Item, offers: Array<Tag>, needs: Array<Tag>, relations: Array<Item>, updatePermission: boolean, loading: boolean, linkItem: (id: string) => Promise<void>, unlinkItem: (id: string) => Promise<void> }) => {
|
export const TabsView = ({ attestations, userType, item, offers, needs, relations, updatePermission, loading, linkItem, unlinkItem }: { attestations: Array<any>, userType: string, item: Item, offers: Array<Tag>, needs: Array<Tag>, relations: Array<Item>, updatePermission: boolean, loading: boolean, linkItem: (id: string) => Promise<void>, unlinkItem: (id: string) => Promise<void> }) => {
|
||||||
|
const addFilterTag = useAddFilterTag()
|
||||||
|
const [activeTab, setActiveTab] = useState<number>()
|
||||||
|
const navigate = useNavigate()
|
||||||
|
|
||||||
const [addItemPopupType] = useState<string>('')
|
const [addItemPopupType] = useState<string>('')
|
||||||
|
|
||||||
@ -34,10 +37,10 @@ export const TabsView = ({ attestations, userType, item, offers, needs, relation
|
|||||||
const updateActiveTab = useCallback((id: number) => {
|
const updateActiveTab = useCallback((id: number) => {
|
||||||
setActiveTab(id)
|
setActiveTab(id)
|
||||||
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search)
|
||||||
params.set("tab", `${id}`);
|
params.set('tab', `${id}`)
|
||||||
const newUrl = location.pathname + "?" + params.toString();
|
const newUrl = location.pathname + '?' + params.toString()
|
||||||
window.history.pushState({}, '', newUrl);
|
window.history.pushState({}, '', newUrl)
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [location.pathname])
|
}, [location.pathname])
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ const addIcon = (icon: string) => {
|
|||||||
return '<svg class="group-icon" stroke="#fff" fill="#fff" stroke-width="0" viewBox="0 0 20 20" aria-hidden="true" height="1.6em" width="1.6em" xmlns="http://www.w3.org/2000/svg"><path d="M10 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM6 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0ZM1.49 15.326a.78.78 0 0 1-.358-.442 3 3 0 0 1 4.308-3.516 6.484 6.484 0 0 0-1.905 3.959c-.023.222-.014.442.025.654a4.97 4.97 0 0 1-2.07-.655ZM16.44 15.98a4.97 4.97 0 0 0 2.07-.654.78.78 0 0 0 .357-.442 3 3 0 0 0-4.308-3.517 6.484 6.484 0 0 1 1.907 3.96 2.32 2.32 0 0 1-.026.654ZM18 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0ZM5.304 16.19a.844.844 0 0 1-.277-.71 5 5 0 0 1 9.947 0 .843.843 0 0 1-.277.71A6.975 6.975 0 0 1 10 18a6.974 6.974 0 0 1-4.696-1.81Z"></path></svg>'
|
return '<svg class="group-icon" stroke="#fff" fill="#fff" stroke-width="0" viewBox="0 0 20 20" aria-hidden="true" height="1.6em" width="1.6em" xmlns="http://www.w3.org/2000/svg"><path d="M10 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6ZM6 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0ZM1.49 15.326a.78.78 0 0 1-.358-.442 3 3 0 0 1 4.308-3.516 6.484 6.484 0 0 0-1.905 3.959c-.023.222-.014.442.025.654a4.97 4.97 0 0 1-2.07-.655ZM16.44 15.98a4.97 4.97 0 0 0 2.07-.654.78.78 0 0 0 .357-.442 3 3 0 0 0-4.308-3.517 6.484 6.484 0 0 1 1.907 3.96 2.32 2.32 0 0 1-.026.654ZM18 8a2 2 0 1 1-4 0 2 2 0 0 1 4 0ZM5.304 16.19a.844.844 0 0 1-.277-.71 5 5 0 0 1 9.947 0 .843.843 0 0 1-.277.71A6.975 6.975 0 0 1 10 18a6.974 6.974 0 0 1-4.696-1.81Z"></path></svg>'
|
||||||
case 'puzzle':
|
case 'puzzle':
|
||||||
return '<svg class="group-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#fff" width="1.6em" height="1.6em"><path d="M11.25 5.337c0-.355-.186-.676-.401-.959a1.647 1.647 0 0 1-.349-1.003c0-1.036 1.007-1.875 2.25-1.875S15 2.34 15 3.375c0 .369-.128.713-.349 1.003-.215.283-.401.604-.401.959 0 .332.278.598.61.578 1.91-.114 3.79-.342 5.632-.676a.75.75 0 0 1 .878.645 49.17 49.17 0 0 1 .376 5.452.657.657 0 0 1-.66.664c-.354 0-.675-.186-.958-.401a1.647 1.647 0 0 0-1.003-.349c-1.035 0-1.875 1.007-1.875 2.25s.84 2.25 1.875 2.25c.369 0 .713-.128 1.003-.349.283-.215.604-.401.959-.401.31 0 .557.262.534.571a48.774 48.774 0 0 1-.595 4.845.75.75 0 0 1-.61.61c-1.82.317-3.673.533-5.555.642a.58.58 0 0 1-.611-.581c0-.355.186-.676.401-.959.221-.29.349-.634.349-1.003 0-1.035-1.007-1.875-2.25-1.875s-2.25.84-2.25 1.875c0 .369.128.713.349 1.003.215.283.401.604.401.959a.641.641 0 0 1-.658.643 49.118 49.118 0 0 1-4.708-.36.75.75 0 0 1-.645-.878c.293-1.614.504-3.257.629-4.924A.53.53 0 0 0 5.337 15c-.355 0-.676.186-.959.401-.29.221-.634.349-1.003.349-1.036 0-1.875-1.007-1.875-2.25s.84-2.25 1.875-2.25c.369 0 .713.128 1.003.349.283.215.604.401.959.401a.656.656 0 0 0 .659-.663 47.703 47.703 0 0 0-.31-4.82.75.75 0 0 1 .83-.832c1.343.155 2.703.254 4.077.294a.64.64 0 0 0 .657-.642Z" /></svg>'
|
return '<svg class="group-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#fff" width="1.6em" height="1.6em"><path d="M11.25 5.337c0-.355-.186-.676-.401-.959a1.647 1.647 0 0 1-.349-1.003c0-1.036 1.007-1.875 2.25-1.875S15 2.34 15 3.375c0 .369-.128.713-.349 1.003-.215.283-.401.604-.401.959 0 .332.278.598.61.578 1.91-.114 3.79-.342 5.632-.676a.75.75 0 0 1 .878.645 49.17 49.17 0 0 1 .376 5.452.657.657 0 0 1-.66.664c-.354 0-.675-.186-.958-.401a1.647 1.647 0 0 0-1.003-.349c-1.035 0-1.875 1.007-1.875 2.25s.84 2.25 1.875 2.25c.369 0 .713-.128 1.003-.349.283-.215.604-.401.959-.401.31 0 .557.262.534.571a48.774 48.774 0 0 1-.595 4.845.75.75 0 0 1-.61.61c-1.82.317-3.673.533-5.555.642a.58.58 0 0 1-.611-.581c0-.355.186-.676.401-.959.221-.29.349-.634.349-1.003 0-1.035-1.007-1.875-2.25-1.875s-2.25.84-2.25 1.875c0 .369.128.713.349 1.003.215.283.401.604.401.959a.641.641 0 0 1-.658.643 49.118 49.118 0 0 1-4.708-.36.75.75 0 0 1-.645-.878c.293-1.614.504-3.257.629-4.924A.53.53 0 0 0 5.337 15c-.355 0-.676.186-.959.401-.29.221-.634.349-1.003.349-1.036 0-1.875-1.007-1.875-2.25s.84-2.25 1.875-2.25c.369 0 .713.128 1.003.349.283.215.604.401.959.401a.656.656 0 0 0 .659-.663 47.703 47.703 0 0 0-.31-4.82.75.75 0 0 1 .83-.832c1.343.155 2.703.254 4.077.294a.64.64 0 0 0 .657-.642Z" /></svg>'
|
||||||
case "staff-snake":
|
case 'staff-snake':
|
||||||
return '<svg class="staff-snake-icon" stroke="currentColor" fill="#fff" stroke-width="0" viewBox="0 0 384 512" height="1.4em" width="1.4em" xmlns="http://www.w3.org/2000/svg"><path d="M222.6 43.2l-.1 4.8H288c53 0 96 43 96 96s-43 96-96 96H248V160h40c8.8 0 16-7.2 16-16s-7.2-16-16-16H248 220l-4.5 144H256c53 0 96 43 96 96s-43 96-96 96H240V384h16c8.8 0 16-7.2 16-16s-7.2-16-16-16H213l-3.1 99.5L208.5 495l0 1c-.3 8.9-7.6 16-16.5 16s-16.2-7.1-16.5-16l0-1-1-31H136c-22.1 0-40-17.9-40-40s17.9-40 40-40h36l-1-32H152c-53 0-96-43-96-96c0-47.6 34.6-87.1 80-94.7V256c0 8.8 7.2 16 16 16h16.5L164 128H136 122.6c-9 18.9-28.3 32-50.6 32H56c-30.9 0-56-25.1-56-56S25.1 48 56 48h8 8 89.5l-.1-4.8L161 32c0-.7 0-1.3 0-1.9c.5-16.6 14.1-30 31-30s30.5 13.4 31 30c0 .6 0 1.3 0 1.9l-.4 11.2zM64 112a16 16 0 1 0 0-32 16 16 0 1 0 0 32z"></path></svg>'
|
return '<svg class="staff-snake-icon" stroke="currentColor" fill="#fff" stroke-width="0" viewBox="0 0 384 512" height="1.4em" width="1.4em" xmlns="http://www.w3.org/2000/svg"><path d="M222.6 43.2l-.1 4.8H288c53 0 96 43 96 96s-43 96-96 96H248V160h40c8.8 0 16-7.2 16-16s-7.2-16-16-16H248 220l-4.5 144H256c53 0 96 43 96 96s-43 96-96 96H240V384h16c8.8 0 16-7.2 16-16s-7.2-16-16-16H213l-3.1 99.5L208.5 495l0 1c-.3 8.9-7.6 16-16.5 16s-16.2-7.1-16.5-16l0-1-1-31H136c-22.1 0-40-17.9-40-40s17.9-40 40-40h36l-1-32H152c-53 0-96-43-96-96c0-47.6 34.6-87.1 80-94.7V256c0 8.8 7.2 16 16 16h16.5L164 128H136 122.6c-9 18.9-28.3 32-50.6 32H56c-30.9 0-56-25.1-56-56S25.1 48 56 48h8 8 89.5l-.1-4.8L161 32c0-.7 0-1.3 0-1.9c.5-16.6 14.1-30 31-30s30.5 13.4 31 30c0 .6 0 1.3 0 1.9l-.4 11.2zM64 112a16 16 0 1 0 0-32 16 16 0 1 0 0 32z"></path></svg>'
|
||||||
default:
|
default:
|
||||||
return ''
|
return ''
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user