1

We are building an Experience Space Addon, with an extension, that is a context button in the menu, when you right click a component.

To know if a user can view or not this button I have to check their permissions making a simple request to an external page (which is hosted in another IIS site).

I would like my addon extension to be visible (available) if a request to "http://xxx/canuserview?userid" returns a "1".

I know how to get the userId, that's not the thing. The problem is, how can I make an http request to that url and enable the extension depending on the result.

2
  • 1
    question is not bit clear, what type of add-on extension? are you looking for add-on package extension to be enabled or disabled in add-on service? or for example add-on extension to enabled and deployed in CME and then only to be make an http request to that url and enable the extension depending on the result.
    – Velmurugan
    Commented Apr 24 at 19:39
  • Thank you for your comment. I just edited the question and added more context. Commented Apr 25 at 4:08

1 Answer 1

2

Availability of the action button is controlled by isAvailable property of useAction hook. Do as many requests you need to calculate availability.

For example:

const useAction = () => {
    const { userProfile } = useUserProfile();
    const [hasAccess, setHasAccess] = useState(false);

    const execute = useCallback(() => {
        console.log('Hello Tridion!');
    }, []);

    const promiseBasedRequest = useCallback(async () => {
        return await fetch(`http://xxx/canuserview?${userProfile?.user?.id.asString}');
    }, [userProfile?.user?.id.asString]);

    useEffect(() => {
        void promiseBasedRequest().then(result => setHasAccess(result === 1);
    }, [promiseBasedRequest]);

    return {
        isAvailable: hasAccess,
        execute,
    };
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.