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
Add module "Not available" option in spaces or for users #6486
Comments
@luke- if you agree with this idea, I can submit a PR. Humhub 1.15 or 1.16? |
Yes, an "Not available" option would be good. But I am not sure if the "Defaults" modal is the right place here. There is also a similar feature here: #3415 |
Yes, I agree the "set as default" is not appropriate for making the module not available on a container types. However, it might add complexity to add another page for that. Perhaps we could rename the "Set as default module" modal box title with something like "Activation in spaces and for user" and then rename the "Deactivated" and "Activated" options with "Deactivated by default" and "Activated by default"? |
For now, I think it's fine to add the "Not available" option to the "Default" modal. If we add a way to restrict modules by container (e.g. Module Wiki for Space A only), we can move this new option to this dialog. |
OK, fine. So I'll add a check of what's chosen into ContentContainerModule::hasContentContainerType(). How should I deal with already activated modules in containers? Should I:
|
Option 1 (just hide) is a little tricky to do because I cannot filter easily content related to "not available" modules in If I had this module ID, I could filter this way: $enabledModuleIds = array_map(static function ($contentContainerModule) {
return $contentContainerModule;
}, $this->container->moduleManager->getAvailable());
$this->query->andWhere(['content.module_id' => $enabledModuleIds]); @luke- What do you think about this idea? Or should I do option 2 (disable the module and delete data)? |
@yurabakhtin Can you please help @funkycram here? |
@yurabakhtin I've started with this: 7e86237 |
@funkycram I think instead of the new code in the function
However I am not sure we need to modify the function because when you update the form "Set as default" with new option "Not available" then it will be impossible to update it again because it will looks like this module is completely disabled from module side: I mean it will looks like the module has the code: public function getContentContainerTypes()
{
return [
Space::class
];
} but really it has: public function getContentContainerTypes()
{
return [
Space::class,
User::class,
];
} So we need to find another place where to disable the module with new "Not available" option. |
@funkycram I think this condition https://github.com/humhub/humhub/blob/develop/protected/humhub/modules/content/components/ContentContainerModuleManager.php#L166-L167: if ($module instanceof ContentContainerModule && $module->isActivated &&
$module->hasContentContainerType(get_class($this->contentContainer))) { should be added with new: ContentContainerModuleManager::getDefaultState(get_class($this->contentContainer), $module->id) !== ContentContainerModuleState::STATE_NOT_AVAILABLE It would be better to wrap the big condition to new separate method like this: public function isAvailableModule($module): bool
{
return $module instanceof ContentContainerModule &&
$module->isActivated &&
$module->hasContentContainerType(get_class($this->contentContainer)) &&
self::getDefaultState(get_class($this->contentContainer), $module->id) !== ContentContainerModuleState::STATE_NOT_AVAILABLE;
} so the conditions will be more readable: if ($this->isAvailableModule($module)) {
$this->_available[$module->id] = $module;
} Please let me know if you need more help from me or if I missed something, |
Thanks very much @yurabakhtin . That's fine and avoids a DB request. How about #6486 (comment) about "How should I deal with already activated modules in containers?", the 2 options and the next comment? Thanks! |
My solution above only hides the already activated modules in containers. Sure we could implement an additional confirmation with question like "Do you want to delete all module data for all Users/Spaces?" like we ask before disabling, or this option can be implemented as checkbox under the new option with text like "[ ] Delete module data for all Users/Space": But I am not sure this cleanup option will be popular, or am I wrong? |
Yes, I agree with you, option 1 is better. Because your solution hides the module, but not the content in the stream. Thanks! |
Yes, you are right, it is a bit more work to filter all content of the "not available" modules instead of just remove contents as we do on disabling. Sure easier to filter content with new column <?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\stream\models\filters;
use humhub\models\Setting;
use humhub\modules\content\components\ContentContainerModule;
use humhub\modules\content\models\ContentContainerModuleState;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
use ReflectionClass;
use Yii;
class ModuleStreamFilter extends StreamQueryFilter
{
public function apply()
{
$this->excludeContainersWithNotAvailableModule(Space::class);
if (!$this->streamQuery->container instanceof Space) {
$this->excludeContainersWithNotAvailableModule(User::class);
}
}
private function excludeContainersWithNotAvailableModule(string $containerClass)
{
$reflectClass = new ReflectionClass($containerClass);
// Find modules with "Not Available" option per User/Space
$moduleIds = Setting::find()
->select('module_id')
->where(['name' => 'moduleManager.defaultState.' . $reflectClass->getShortName()])
->andWhere(['value' => ContentContainerModuleState::STATE_NOT_AVAILABLE])
->column();
if (empty($moduleIds)) {
return;
}
$excludedContentClasses = [];
foreach ($moduleIds as $moduleId) {
$module = Yii::$app->getModule($moduleId);
if ($module instanceof ContentContainerModule) {
$excludedContentClasses = array_merge($excludedContentClasses, $module->getContentClasses());
}
}
if (empty($excludedContentClasses)) {
return;
}
$this->query->andWhere(['OR',
['!=', 'contentcontainer.class', $containerClass],
['AND', ['contentcontainer.class' => $containerClass], ['NOT IN', 'content.object_model', $excludedContentClasses]]
]);
}
} Could you please test it? |
Thanks very much @yurabakhtin , it works perfectly! I've changed slightly the |
@funkycram Thank you for the PR, I have reviewed it and described why we need the changes, please see my remarks in the PR. |
@yurabakhtin Thanks very much for the explanation. Now I understand much better how it works. I've applied your solution in commit 05cbb72 and I tested all combinaisons (in space, user and dashboard), it works fine in all cases! |
@funkycram I would prefer to merge this into v1.16. Is the PR urgent? |
@funkycram @luke- Before merging I would like to fix the issue from here #6499 (comment) at least for the "Files" module. Also I think probably we should exclude the blocked classes from the stream filter "Content Type", at least for Space wall stream, but not sure for User wall stream, because there it is not easy to find all spaces where user posted. |
@luke- yes, let's wait for Humhub 1.16 (I've updated the CHANGELOG-DEV). @yurabakhtin sorry, I wasn't notified about your review (it's not the first time I'm not notified and I also remember you wasn't notified once about one of my review mentioning you). So I reply to your review here.
Thanks for your investigation.
Perhaps we could update these 3 modules (Files, External Calendar and Gallery) so they are ready when this "Not available" option arrives in Humhub 1.16?
@yurabakhtin yes sure. What do your think about this commit (tested, it works)? |
I agree we should update the missed
I have tested it works well, thank you! |
Thanks @yurabakhtin Yes, this was a forgotten line. Removed in commit b9e7d34 |
@yurabakhtin we also have the Share Between module missing
|
@luke- @funkycram I find the method |
@luke- I have reviewed all modules and added the missed |
@yurabakhtin @funkycram Sorry for being so late in giving my feedback: I would actually delete||show already created content at "Always deactivated". The filtering requires a lot of code for quite an edge case. This costs performance and has to be done in other places like search as well. What do you think? Should we stay with the current solution? @Semir1212 Is "Not available" ok from wording perspective? |
@luke- Yes sure, the filtering requires more code so the performance will be slower as before. But if we need to keep all content for case when the option was set by mistake or as experiment then we might implement new Content State like |
Yes. Maybe something similar to the Private/Public Space Visibility Toggle.
Sounds good but I'm not sure how to handle changes back to available. Delete is probably the cleanest solution. @funkycram What do you think? |
@luke- Ah yes, you are right, it will be not right to restore all records from |
Yes, that's okay for me. Do you confirm it's a better solution than #6486 (comment) -> "unless I add a column..."?
Yes |
There is a draft PR which changes the DB structure so the "module_id" would be available. #6217 - Maybe we can change this later,... |
Yes @luke- |
@luke- @yurabakhtin commit cd10769 @luke- To confirm module disabling for users and spaces, I didn't choose your modal box solution because the form is already in a modal box. What do you think of the solution of this commit (I tried to make something simple in the code)? |
@marc-farre Thanks looks good for me! @Semir1212 Can you please take a look over the red warning text? |
@luke- @marc-farre @yurabakhtin The module is currently being used by X users or spaces. If you change its availability, all content created with the module will be lost. Proceed? |
Thanks @Semir1212 . Done in commit 5b0d274 @luke- @yurabakhtin full PR: #6499 |
@marc-farre Thanks, looks fine for me. Is target v1.16 ok for you? @yurabakhtin Can you please also do a quick review? |
Yes 1.16 is fine for me. It's only a personal contribution, not a customer request. Thanks for asking! |
@luke- I agree the new changes. |
Thanks! |
Is your feature request related to a problem? Please describe.
Example with the wiki module.
You want to allow activating the module in spaces but not for users.
Describe the solution you'd like
The text was updated successfully, but these errors were encountered: