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

Allow update topics for a post #86

Merged
merged 7 commits into from
May 6, 2022
Merged

Conversation

yurabakhtin
Copy link
Contributor

Issue: #85

@luke-
Copy link
Contributor

luke- commented Apr 13, 2022

@yurabakhtin Does it really make sense to implement topic handling only at Post endpoint like this? What if we also want to set topics in Polls, Wiki or other content types?.

Wouldn't it be better to create a central possibility somewhere at the content endpoint?

@yurabakhtin
Copy link
Contributor Author

@luke- Really I made the changes in base controller BaseContentController which is used for all content active record controllers like PollsController, so we just need to update doc files in each modules.
But some modules at least the PollsController overrides the actions of the BaseContentController, so I have updated it to work with new content topics format in the PR humhub/polls#95.
I will review all other modules to do the same changes where it is required.

@yurabakhtin
Copy link
Contributor Author

@luke- Same changes for wiki module - humhub/wiki#236

Please note this module already had the topics supporting https://www.humhub.com/en/marketplace/wiki/docs/swagger/wiki.html#tag/Wiki-Page/paths/~1wiki~1container~1{id}/post, but it was available to update topics only by IDs, so I just added new possibility to update topics by names.

@yurabakhtin
Copy link
Contributor Author

@luke- Same changes for tasks module - humhub/tasks#182

@yurabakhtin
Copy link
Contributor Author

@luke- Changes for calendar module - humhub/calendar#282

@yurabakhtin
Copy link
Contributor Author

@luke- I have updated all modules, see comments above.

components/BaseContentController.php Show resolved Hide resolved
@@ -68,7 +68,7 @@ paths:
- data
properties:
data:
$ref: "#/definitions/Post"
$ref: "#/definitions/PostForm"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the need to have two definitions. Post and PostForm which are almost identical.

This is just only due to Content and ContentForm?

Couldnt we integrate the Topics with in ContentMetadata`?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@luke- We cannot use the same object/structure for a request data and for a response data.
For example, response data contains id, but we should not allow to send/request this field because it cannot be updated. Also we should not allow to update other fields like guid, created_at which exist in the object ContentMetadata.
So I decided to create the separate object ContentForm in order to keep there only fields which are allowed in request data.

Copy link
Contributor

Choose a reason for hiding this comment

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

@yurabakhtin It is possible to flag attributes in Swagger with readOnly or writeOnly.
https://swagger.io/docs/specification/data-models/data-types/

e.g. for id we already use this:
https://github.com/humhub/rest/blob/master/docs/swagger/content.yaml#L212

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@luke- I tested the flags readOnly or writeOnly, but a generated HTML file doesn't hide field depending on these flags in request/response:

test_read_only

But we need this:

array_types

I.e. in request and response we have the field with key topics but it has a different format.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@luke- Please review my changes in the commit 4f3d9d9

I found how to use readOnly and writeOnly flags only for definitions/components but I cannot find how to use these flags for different examples but with same key, as we need for property/key topics.

For request part we need only array on strings:

  • ["First topic", "Second tag"]

For response - array of objects:

[
  { "id": 1, "name": "First topic" },
  { "id": 2, "name": "Second tag" }
]

So in the commit I created a new key topics-array, but in php code we still have topics for request data.
If we stop on this solution we should modify php code and accept topics-array on request side.
I.e. as I wrote above the main reason why I created a separate object/component/definition is that topics has a different schema in request and response parts.

Copy link
Contributor

@luke- luke- May 5, 2022

Choose a reason for hiding this comment

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

@yurabakhtin Thanks the commit looks fine. But can't we just use the "Id" in the Topic example as ReadOnly. Or did is missed something here?

For reading:

[
  { "id": 1, "name": "First topic" },
  { "id": 2, "name": "Second tag" } }
]

Writing:

[
  { "name": "First topic" },
  { "name": "Second tag" }
]

I would also like it if the ContentMetadata were not completely readOnly, but you could control the Visibility & Archived & Pinned there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@luke- New changes in commit 3f9de19:

new_topics_metadata_schema

If this is ok then let me know to update related PRs where ContentForm definition is used:

Copy link
Contributor

Choose a reason for hiding this comment

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

@yurabakhtin Thanks for the effort, I really like it that way. One last request:
Can we not use integers here for clearly boolean values (archived, pinned, locked_comments)?
With Visibility it is of course a bit different, because there are different levels.

Copy link
Contributor Author

@yurabakhtin yurabakhtin May 6, 2022

Choose a reason for hiding this comment

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

@luke-

Can we not use integers here for clearly boolean values (archived, pinned, locked_comments)?

Commit c8dd1ff

The related PRs have been updated as well:

docs/swagger/content.yaml Outdated Show resolved Hide resolved
@luke- luke- merged commit fb4fc41 into master May 6, 2022
@luke- luke- deleted the enh/85-update-content-topics branch May 6, 2022 11:20
Comment on lines +510 to +528
protected function updateLockedComments(ContentActiveRecord $activeRecord, array $data): bool
{
if (!isset($data['locked_comments'])) {
return true;
}

if (!in_array($data['locked_comments'], [0, 1])) {
$activeRecord->addError('locked_comments', 'Wrong field "locked_comments" value!');
return false;
}

if (!$activeRecord->content->canLockComments()) {
$activeRecord->addError('locked_comments', 'You cannot lock comments of the Content!');
return false;
}

$activeRecord->content->locked_comments = $data['locked_comments'];
return $activeRecord->content->save();
}

Choose a reason for hiding this comment

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

#88 related?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@donni106 Yes, partly related, I answered there #88 (comment), thank you for the report!

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

Successfully merging this pull request may close these issues.

3 participants