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

Added parameter to disallow creating of rooms with public access #8082

Closed
wants to merge 3 commits into from

Conversation

pboguslawski
Copy link
Contributor

Added spreed application config parameter public_rooms_allowed to disallow
creating of rooms with public (guest via link) access (i.e. for internal
Nextcloud setups). Use

occ config:app:set spreed public_rooms_allowed --value 'yes'

to allow (default if not set) and

occ config:app:set spreed public_rooms_allowed --value 'no'

to disallow creating of rooms with public access.

Related: #521
Author-Change-Id: IB#1126215
Signed-off-by: Pawel Boguslawski pawel.boguslawski@ib.pl

Added spreed application config parameter `public_rooms_allowed` to disallow
creating of rooms with public (guest via link) access (i.e. for internal
Nextcloud setups). Use

```
occ config:app:set spreed public_rooms_allowed --value 'yes'
```

to allow (default if not set) and

```
occ config:app:set spreed public_rooms_allowed --value 'no'
```

to disallow creating of rooms with public access.

Related: nextcloud#521
Author-Change-Id: IB#1126215
Signed-off-by: Pawel Boguslawski <pawel.boguslawski@ib.pl>
@nickvergessen nickvergessen added this to the 💟 Next Major (26) milestone Oct 3, 2022
@nickvergessen nickvergessen added 3. to review enhancement feature: chat 💬 Chat and system messages feature: settings ⚙️ Settings and config related issues feature: api 🛠️ OCS API for conversations, chats and participants feature: frontend 🖌️ "Web UI" client labels Oct 3, 2022

// Force group room if public room was requested and public rooms are disallowed.
if (($type === Room::TYPE_PUBLIC) && ($this->config->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'no')) {
$type = Room::TYPE_GROUP;
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if we should simply convert it. Or just error with a 400 Bad Request and a message the clients can display.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Conversion was choosen because spreed code ignores errors returned by modified functions and this seems to be safer. Conversion should never happen because function should be not available in UI also (and if bad guys will try to modify POST, will get group conversation which should not hurt regular users).

Copy link
Member

Choose a reason for hiding this comment

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

That assumes all clients got updated in the meantime :)

Copy link
Contributor Author

@pboguslawski pboguslawski Oct 3, 2022

Choose a reason for hiding this comment

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

Sorry, we use web UI only - feel free to extend it for other required areas if necessary (not experienced enough in nc devel to propose it now).

Copy link
Member

Choose a reason for hiding this comment

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

You can fix it with one step by moving it to RoomService::createConversation and throwing an exception or basically adjust this list here:

if (!\in_array($type, [
Room::TYPE_GROUP,
Room::TYPE_PUBLIC,
Room::TYPE_CHANGELOG,
], true)) {
throw new InvalidArgumentException('type');
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

type is property of Room not RoomService so verification should take place in Room class to avoid future problems (i.e. code outside of RoomService will create/change room of disabled type). Seems that now Room::setType and Room constructor are the best places for this verification but code using it should properly handle errors when disabled type is passed. Please let me know if its possible to just throw exception in Room methods mentioned above without messing with room type conversions (there should not be any other trash left after such exception - not sure if it would be safe now).

Comment on lines +265 to +268
// Force group room if public room was requested and public rooms are disallowed.
if (($type === self::TYPE_PUBLIC) && ($this->config->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'no')) {
$type = self::TYPE_GROUP;
}
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct. You want to do this change on the RoomService, not the model.
But see comment above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified places where choosen to avoid problems with lack of return errors handling. If you still recommend moving it elswhere - please suggest detailed change.

Copy link
Member

Choose a reason for hiding this comment

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

As per above, you should do it only in the RoomService

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't see any mention of setType in RoomService and this method may be called so must verify room type also.


$this->initialState->provideInitialState(
'public_rooms_allowed',
$this->serverConfig->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'yes'
Copy link
Member

Choose a reason for hiding this comment

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

We need to expose this to the mobile clients as a capability so they can also hide the features accordingly.

Copy link
Contributor Author

@pboguslawski pboguslawski Oct 3, 2022

Choose a reason for hiding this comment

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

This mod was created for web UI. Not experienced in nextcloud devel nor using mobile app so please suggest required changes if necessary.

Copy link
Member

Choose a reason for hiding this comment

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

Basically add a line like this which in addition also checks your config:

$capabilities['config']['conversations']['can-create'] = $user instanceof IUser && !$this->talkConfig->isNotAllowedToCreateConversations($user);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not experienced with capabilities in Nextcloud - please create change suggestion and will just accept it to this PR or make separate PR to adjust it.

Copy link
Member

@marcoambrosini marcoambrosini left a comment

Choose a reason for hiding this comment

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

tested and works 👌

Copy link
Member

@nickvergessen nickvergessen left a comment

Choose a reason for hiding this comment

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

  • Also RoomService::setType() should check the config.
  • RoomController::addParticipantToRoom should not allow to add email addresses to a conversation (which also makes the room public)
  • Since emails are then not allowed anymore, we should also not autocomplete them here:
    shareTypes.push(SHARE.TYPE.EMAIL)


// Force group room if public room was requested and public rooms are disallowed.
if (($type === Room::TYPE_PUBLIC) && ($this->config->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'no')) {
$type = Room::TYPE_GROUP;
Copy link
Member

Choose a reason for hiding this comment

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

You can fix it with one step by moving it to RoomService::createConversation and throwing an exception or basically adjust this list here:

if (!\in_array($type, [
Room::TYPE_GROUP,
Room::TYPE_PUBLIC,
Room::TYPE_CHANGELOG,
], true)) {
throw new InvalidArgumentException('type');
}

Comment on lines +265 to +268
// Force group room if public room was requested and public rooms are disallowed.
if (($type === self::TYPE_PUBLIC) && ($this->config->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'no')) {
$type = self::TYPE_GROUP;
}
Copy link
Member

Choose a reason for hiding this comment

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

As per above, you should do it only in the RoomService


$this->initialState->provideInitialState(
'public_rooms_allowed',
$this->serverConfig->getAppValue('spreed', 'public_rooms_allowed', 'yes') === 'yes'
Copy link
Member

Choose a reason for hiding this comment

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

Basically add a line like this which in addition also checks your config:

$capabilities['config']['conversations']['can-create'] = $user instanceof IUser && !$this->talkConfig->isNotAllowedToCreateConversations($user);

@pboguslawski
Copy link
Contributor Author

  • Also RoomService::setType() should check the config.

    • RoomController::addParticipantToRoom should not allow to add email addresses to a conversation (which also makes the room public)

    • Since emails are then not allowed anymore, we should also not autocomplete them here:

      shareTypes.push(SHARE.TYPE.EMAIL)

Verification should be placed in Room class in all methods capable of setting/changing type (now constructor and setType probably) but code using Room must be prepared for errors/exceptions (not sure if already is) so please propose better solution than conversion proposed in this change (as suggestions or separate PR).

…owed

Fixes: a38fdfd
Related: nextcloud#8082 (review)
Author-Change-Id: IB#1126215
Signed-off-by: Pawel Boguslawski <pawel.boguslawski@ib.pl>
@pboguslawski
Copy link
Contributor Author

pboguslawski commented Oct 17, 2022

4c645ce disables adding e-mails to room when public rooms are disabled.

@nickvergessen
Copy link
Member

Sorry for the lack of responsiveness lately.
I still have your PR on my todo list and hopefully will reach it this week.

nickvergessen pushed a commit that referenced this pull request Nov 16, 2022
…owed

Fixes: a38fdfd
Related: #8082 (review)
Author-Change-Id: IB#1126215
Signed-off-by: Pawel Boguslawski <pawel.boguslawski@ib.pl>
nickvergessen pushed a commit that referenced this pull request Nov 16, 2022
…owed

Fixes: a38fdfd
Related: #8082 (review)
Author-Change-Id: IB#1126215
Signed-off-by: Pawel Boguslawski <pawel.boguslawski@ib.pl>
@nickvergessen
Copy link
Member

Hi there, I copied your branch into our organisation and sent you an invite.
This allows us to better collaborate on the feature.

I rebased it on latest master and did some fixes and changes.
New pull request is here: #8357

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review enhancement feature: api 🛠️ OCS API for conversations, chats and participants feature: chat 💬 Chat and system messages feature: frontend 🖌️ "Web UI" client feature: settings ⚙️ Settings and config related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants