Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Draft] [Example] Integrate a webspace specific setting administration interface #106

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

alexander-schranz
Copy link
Member

@alexander-schranz alexander-schranz commented Jan 30, 2023

This is not yet working as sulu/sulu#6985 is not yet part of the Sulu Core. Workaround is going over a list currently.

What's in this PR?

Create a webspace specific setting entity. To demostrate how to add a new form

Sulu Admin with additional Webspace Settings Tab

TODO

Related

@alexander-schranz alexander-schranz changed the title Example/webspace setting entity [Draft] [Example] Integrate a webspace specific setting administration interface Jan 30, 2023
->setResourceKey(WebspaceSetting::RESOURCE_KEY)
->setTabTitle('app.webspace_settings')
->setParent(PageAdmin::WEBSPACE_TABS_VIEW)
->setOption('routerAttributesToFormRequest', ['webspace'])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be get part of the createResourceTabViewBuilder as addRouterAttributesToFormRequest when implemented

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be get part of the createResourceTabViewBuilder as addRouterAttributesToFormRequest when implemented

Is there anything planed to get the webspace in createResourceTabViewBuilder?
THX for info

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Builder is generally for all webspaces. To get the webspace in the endpoint which this view is for you need $request->query->get('webspace');. If you want to hide a tab you may could try use tabCondition but I'm not sure which data is available in the condition itself.

Copy link

@hual7 hual7 Jun 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is different in the admin build, so I run in a permission view error because I didn't get the webspace key with $request->query->get('webspace')
Is there any sulu js extension in the example, that is not loaded via bin/console sulu:admin:update-build?
THX

@alexander-schranz alexander-schranz added the Example Example implementations label Jan 30, 2023
@LCorentinL
Copy link

LCorentinL commented Mar 7, 2024

Hello @alexander-schranz
image
This is the error i get with your code on /admin/api/webspace-settings/-

In fact i set the right for my user here :
image

After a little analyse, i think it comes from :

self::getWebspaceSettingSecurityContext('#webspace#') => $this->getSecurityContextPermissions(),

I made this for debug :
public static function getWebspaceSettingSecurityContext($webspaceKey): string { var_dump($webspaceKey); return \sprintf('%s%s.%s', PageAdmin::SECURITY_CONTEXT_PREFIX, $webspaceKey, 'settings'); }

and here are the dump :
string(4) "demo" string(10) "#webspace#"

I think the #webspace# is not interpreted and i get the sulu.webspaces..settings instead of sulu.webspaces.demo.settings

UPDATE :
I tried adding 'demo' instead of #webspace# for testing, and it's not that.
So the bug comes from :
`
public function getSecurityContext()
{
$request = $this->requestStack->getCurrentRequest();

    return WebspaceSettingAdmin::getWebspaceSettingSecurityContext($request->query->get('webspace'));
}

`

In WebspaceSettingController.php

$request->query->get('webspace' => NULL

I also dump $request->query and this i what i get :
object(Symfony\Component\HttpFoundation\InputBag)#14 (1) { ["parameters":protected]=> array(0) { } }

It's linking to this: #112

Thank you

@manuxi
Copy link

manuxi commented Mar 26, 2024

Facing the same problem here:

Error: 'Permission \"view\" in localization \"\" for context \"sulu.webspaces..settings\" and object with id \"\" and type \"\" not granted'

It seems that the sulu_core.webspace.webspace_manager injected in SettingsAdmin returns an empty element (only have one webspace here).
For debugging purposes I added the "string" type hint to public static function getWebspaceSettingSecurityContext(string $webspaceKey): string - the prevously fetch of the key of the webspace fails.

foreach ($this->webspaceManager->getWebspaceCollection() as $webspace) {
            $webspace->getKey(); // this is null as well as $webspace->getName();
}

@alexander-schranz
Copy link
Member Author

This is still a Draft. Until sulu/sulu#6985 is part of the core this will not work as expected yet.

@alexander-schranz
Copy link
Member Author

As a workaround you may can have a look at the https://github.com/bitExpert/sulu-securitytxt-bundle by @shochdoerfer to go over the FormListOverlay View.

@manuxi
Copy link

manuxi commented Jul 1, 2024

As a workaround you may can have a look at the https://github.com/bitExpert/sulu-securitytxt-bundle by @shochdoerfer to go over the FormListOverlay View.

Don't know exactly what you mean here - I went through the sulu-securitytxt-bundle but can not see how it could help here.
As described above and here the request object is null in my webspace settings controller. Tried it with several attempts (DI, Requeststack, typehint, etc.) - but cant get anything. It's always null.

@shochdoerfer
Copy link

@manuxi the only thing I did was to fake it :) I made the webspace_key in my entity unique. Anytime you want to save an additional record, it will fail. That was the best implementation I could come up with.

I remember I experimented a lot with the different settings and how to catch errors on the server side, but I never achieved a fully working implementation. Thus, using the table view and allowing only to save 1 element was the best alternative I could come up with. Eagerly waiting for #6985 to get merged :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Example Example implementations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants