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 funtion get_allow_discussion_value #1655

Closed
wants to merge 0 commits into from

Conversation

Akshat2Jain
Copy link
Member

@Akshat2Jain Akshat2Jain commented Jun 13, 2023

Description

This pr aims to add the function

def get_allow_discussion_value(context, request):
    return getMultiAdapter((context, request), name="conversation_view").enabled()

in dxcontent.py and site.py

Why

Plone Site serializer and the Dexterity serializer return the same value for the "allow_discussion" field. Rather than duplicating the code, creating a separate function that can be called by both serializers to set the value consistently.

This pr related to the issue mentioned in volto project

fixes plone/volto#4758

@mister-roboto
Copy link

@Akshat2Jain thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@netlify
Copy link

netlify bot commented Jun 13, 2023

Deploy Preview for plone-restapi canceled.

Name Link
🔨 Latest commit 24f25d7
🔍 Latest deploy log https://app.netlify.com/sites/plone-restapi/deploys/64c8dc620f8eb2000889f2a7

@wesleybl
Copy link
Member

@Akshat2Jain see if you can create a branch in the repository itself in plone.restapi. Github Actions tests were not run, because the PR was made from a fork

@Akshat2Jain
Copy link
Member Author

@Akshat2Jain see if you can create a branch in the repository itself in plone.restapi. Github Actions tests were not run, because the PR was made from a fork

Hey @wesleybl, I don't have access rights to create a branch

@stevepiercy
Copy link
Contributor

To allow tests to run on PRs from forks, we need to update the GitHub Workflows, similar to what we did in Volto: plone/volto@5808b78

We restricted access across the Plone GitHub organization for members of Contributors. See https://community.plone.org/t/gsoc-students-please-focus-on-your-application-restrictions-on-developer-team-access-on-github/17041 for more information.

I created a new issue to deal with the above at #1656

@Akshat2Jain meanwhile would you please add a change log entry, per instructions in https://6.docs.plone.org/contributing/index.html#change-log-entry. Thank you!

Copy link
Member

@jensens jensens left a comment

Choose a reason for hiding this comment

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

Please make the code conditional, because soon, for Plone 6.1, plone.app.discussion becomes an optional core addon. It can be absent as a package or not installed via GenricSetup.

@wesleybl
Copy link
Member

wesleybl commented Jun 16, 2023

It can be absent as a package or not installed via GenricSetup.

@jensens checking if the object has the allow_discussion attribute would be more performant than using is_product_installed? Or would a try/except be fine?

@wesleybl
Copy link
Member

hmm i think checking if the result dictionary has allow_discussion key would be better.

@Akshat2Jain
Copy link
Member Author

hmm i think checking if the result dictionary has allow_discussion key would be better.

I think this will be a more desirable solution approach because the code remains compatible with Plone 6.1 irrespective of whether the plone.app.discussion package is present or not.

Could you please advise on which approach you recommend and also how to do it? @wesleybl
Thanks!

@wesleybl
Copy link
Member

@Akshat2Jain I think it would be something like:

if "allow_discussion" in result:
    result["allow_discussion"] = get_allow_discussion_value(self.context, self.request)

You need to rebase with master before continuing.

@Akshat2Jain
Copy link
Member Author

@Akshat2Jain I think it would be something like:

if "allow_discussion" in result:
    result["allow_discussion"] = get_allow_discussion_value(self.context, self.request)

Yeah! This is also correct but I have done something this.

def has_allow_discussion(result):
    return 'allow_discussion' in result
 if has_allow_discussion(result):
        result["allow_discussion"] = getMultiAdapter(
            (self.context, self.request), name="conversation_view"
        ).enabled()

But this will increase no of lines of code!
@wesleybl

Thanks!

@jensens
Copy link
Member

jensens commented Jun 22, 2023

Some remarks:

  1. getMultiAdapter((context, request), name="conversation_view").enabled() is an expensive call.
  2. in the diff it looks like there is some indent wrong.
  3. please DRY in code.

@wesleybl
Copy link
Member

getMultiAdapter((context, request), name="conversation_view").enabled() is an expensive call.

Today it is already used. See:

result["allow_discussion"] = getMultiAdapter(
(self.context, self.request), name="conversation_view"
).enabled()

@Akshat2Jain
Copy link
Member Author

@wesleybl . I have made the changes. Can you review it.

@wesleybl
Copy link
Member

@Akshat2Jain by having several commits, I suspect that you were making the commits through the github website. I recommend that next time, you make a clone of the repository and put several files in one commit. That way we won't have multiple commits.

@wesleybl
Copy link
Member

Please make the code conditional, because soon, for Plone 6.1, plone.app.discussion becomes an optional core addon.

@jensens since plone.app.discussion will no longer be part of the core, I'm wondering if plone.restapi should be worrying about it. Could it be that instead of a condition, shouldn't we simply remove the allow_discussion handler? Shouldn't plone.app.discussion be the one to worry about?

Do we plan to have a plone.restapi 9 for Plone 6.1? If not, shouldn't it have, to handle situations like this, and to remove support for Plone 5.2?

Copy link
Member

@wesleybl wesleybl left a comment

Choose a reason for hiding this comment

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

src/plone/restapi/serializer/dxcontent.py Outdated Show resolved Hide resolved
src/plone/restapi/serializer/dxcontent.py Outdated Show resolved Hide resolved
src/plone/restapi/serializer/dxcontent.py Outdated Show resolved Hide resolved
src/plone/restapi/serializer/site.py Outdated Show resolved Hide resolved
@jensens
Copy link
Member

jensens commented Jun 26, 2023

Conditional support is fine. It is the same as currently with p.a.iterate, in near future with multilingual and there may add up other packages. Plan is to reduce the Plone core (the packages between plone.base and CMFPlone) and add them as core-addons to the space between CMFPlone and the Plone integration package. Distributions then can choose to have them or not.

@Akshat2Jain
Copy link
Member Author

@wesleybl can you review it?

Copy link
Member

@wesleybl wesleybl left a comment

Choose a reason for hiding this comment

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

Pease make a clone of the repository and put several files in one commit. That way we won't have multiple commits.

Checks at Some checks were not successful:

#1655 (comment)

must pass.

src/plone/restapi/serializer/dxcontent.py Outdated Show resolved Hide resolved
src/plone/restapi/serializer/dxcontent.py Outdated Show resolved Hide resolved
src/plone/restapi/serializer/dxcontent.py Outdated Show resolved Hide resolved
src/plone/restapi/serializer/site.py Outdated Show resolved Hide resolved
src/plone/restapi/serializer/site.py Outdated Show resolved Hide resolved
src/plone/restapi/serializer/site.py Outdated Show resolved Hide resolved
@Akshat2Jain
Copy link
Member Author

@wesleybl . I have made the changes.
Can you tell me where exactly black test are failing

@wesleybl
Copy link
Member

wesleybl commented Jul 5, 2023

@Akshat2Jain the github action output itself says what needs to be changed. to see:

https://github.com/plone/plone.restapi/actions/runs/5462642539/jobs/9942277773?pr=1655#step:5:20

But ideally, you have black installed locally, and format the code before committing. You can install it by running the make command inside the plone.restapi folder. After running make, you can run make black. This will automatically format the code for you. Some IDEs also have integration with black, to format the code when saving.

The make command will also install all of the package's dependencies. Then you can run the tests locally, with the command make test.

news/4758.bugfix Outdated
@@ -0,0 +1,6 @@
add the function
Copy link
Member

Choose a reason for hiding this comment

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

Use the PR number in the file name.

news/4758.bugfix Outdated
Comment on lines 3 to 4
def get_allow_discussion_value(context, request):
return getMultiAdapter((context, request), name="conversation_view").enabled()
Copy link
Member

Choose a reason for hiding this comment

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

It is not necessary to have code in Changes.

src/plone/restapi/serializer/dxcontent.py Outdated Show resolved Hide resolved
Comment on lines 134 to 135
if "allow_discussion" in result:
result["allow_discussion"] = get_allow_discussion_value(self.context, self.request, result)
Copy link
Member

Choose a reason for hiding this comment

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

The test is being done inside the function. So we shouldn't do the test here. Assignment is also being done in the function.

Suggested change
if "allow_discussion" in result:
result["allow_discussion"] = get_allow_discussion_value(self.context, self.request, result)
get_allow_discussion_value(self.context, self.request, result)

@@ -121,6 +122,8 @@ def __call__(self, version=None):
for brain in batch
]

result["allow_discussion"] = get_allow_discussion_value(self.context, self.request, result)
Copy link
Member

Choose a reason for hiding this comment

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

The assignment is being done inside the function. So we shouldn't do assignment here.

Suggested change
result["allow_discussion"] = get_allow_discussion_value(self.context, self.request, result)
get_allow_discussion_value(self.context, self.request, result)

@stevepiercy
Copy link
Contributor

But ideally, you have black installed locally, and format the code before committing. You can install it by running the make command inside the plone.restapi folder. After running make, you can run make black. This will automatically format the code for you. Some IDEs also have integration with black, to format the code when saving.

The make command will also install all of the package's dependencies. Then you can run the tests locally, with the command make test.

This should go into the documentation: https://6.docs.plone.org/plone.restapi/docs/source/contributing/index.html. It's not in the README. At the very least, an output of the make help command would be good.

@Akshat2Jain
Copy link
Member Author

But ideally, you have black installed locally, and format the code before committing. You can install it by running the make command inside the plone.restapi folder. After running make, you can run make black. This will automatically format the code for you. Some IDEs also have integration with black, to format the code when saving.

The make command will also install all of the package's dependencies. Then you can run the tests locally, with the command make test.

I have run the make black and it formatted around 93 files. Should I commit all those files? @wesleybl

@wesleybl
Copy link
Member

wesleybl commented Jul 6, 2023

I have run the make black and it formatted around 93 files. Should I commit all those files? @wesleybl

It shouldn't format so many files. What version of black is he using? Please show the command output:

./bin/black --version

Can you please also inform the output of make black?

@Akshat2Jain
Copy link
Member Author

It shouldn't format so many files. What version of black is he using? Please show the command output:

./bin/black --version

Can you please also inform the output of make black?

@wesleybl
Version

black, 23.3.0 (compiled: yes)
Python (CPython) 3.10.6

output of make black

All done! ✨ 🍰 ✨
93 files formatted, 302 files left unchanged.

@wesleybl
Copy link
Member

wesleybl commented Jul 6, 2023

@Akshat2Jain the Makefile is installing the latest from black:

bin/pip install black || true

Meanwhile, CI is installing version of versions.cfg:

run: pip install click==$(awk '/^click =/{print $NF}' versions.cfg) black==$(awk '/^black =/{print $NF}' versions.cfg)

Would you like to do another PR, to install the version of black and click that is in versions.cfg in Makefile?

You could also upgrade to the latest versions of click and black in versions.cfg

You need to update your fork's master branch with the original repository's master branch first.

Copy link
Member

@wesleybl wesleybl left a comment

Choose a reason for hiding this comment

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

Tests are failing. At the end of the CI tracebak it indicates the error. For example:

https://github.com/plone/plone.restapi/actions/runs/5572932135/jobs/10179541947?pr=1655#step:10:789

You can run the tests locally with make test

@Akshat2Jain
Copy link
Member Author

Tests are failing. At the end of the CI tracebak it indicates the error. For example:

https://github.com/plone/plone.restapi/actions/runs/5572932135/jobs/10179541947?pr=1655#step:10:789

You can run the tests locally with make test

while running make test I am getting this error


bin/test
/bin/bash: line 1: bin/test: No such file or directory
make: *** [Makefile:76: test] Error 127

@wesleybl

@stevepiercy
Copy link
Contributor

@Akshat2Jain did you issue the command from the root of the Volto repository?

@Akshat2Jain
Copy link
Member Author

@Akshat2Jain did you issue the command from the root of the Volto repository?

did you mean from the root of plone.restapi

@stevepiercy
Copy link
Contributor

Oops, yes. Sorry, I am multitasking.

@stevepiercy
Copy link
Contributor

Actually, I tried make test, and got the same result as you.

So I issued just make, and it is installing the package and its dependencies. When it is complete, I will run make test again, and report back the results.

@stevepiercy
Copy link
Contributor

make test runs the tests for me. Perhaps try again with make clean, then make, and finally make test?

@Akshat2Jain
Copy link
Member Author

Akshat2Jain commented Jul 18, 2023

make test runs the tests for me. Perhaps try again with make clean, then make, and finally make test?

Yup, Now it is running but I don't know why, I did these steps 2-3 times and at that time it was not running for me.

Copy link
Contributor

@stevepiercy stevepiercy left a comment

Choose a reason for hiding this comment

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

I reviewed only the news item. It still needs review by a maintainer.

news/1665.bugfix Outdated
@@ -0,0 +1 @@
added the function get_allow_discussion_value(context, request) returns True if discussion is allowed and False if not, based on the enabled status of the "conversation_view" adapter.@Akshat2Jain
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
added the function get_allow_discussion_value(context, request) returns True if discussion is allowed and False if not, based on the enabled status of the "conversation_view" adapter.@Akshat2Jain
Added the function `get_allow_discussion_value(context, request)`. It returns `True` if discussion is allowed, or `False` if not, based on the enabled status of the `conversation_view` adapter. @Akshat2Jain

@wesleybl
Copy link
Member

@jensens @sneridagh a test was made to try to verify that plone.app.discussion is installed:

if "allow_discussion" in result:

However, when plone.app.discussion is installed and enabled globally, but a content doesn't have the behavior, allow_discussion is not added to the json. This test failed:

def test_allow_discussion_global_enabled_but_instance_has_no_discussion_behavior(

See:

https://github.com/plone/plone.restapi/actions/runs/5586686877/jobs/10211032234?pr=1655#step:10:33

Any other test to see if plone.app.discussion is installed would be more costly, and would have to be done on every request.

So I ask, is it ok if we don't have the allow_discussion key in this situation?

@wesleybl
Copy link
Member

@jensens @sneridagh any opinions here?

@wesleybl
Copy link
Member

@davisagli any opinions here? See comment on @jensens' review and #1655 (comment).

@wesleybl wesleybl requested a review from davisagli July 25, 2023 12:37
@Akshat2Jain
Copy link
Member Author

@davisagli @jensens any suggestions? we are close to completing this

@wesleybl
Copy link
Member

@jensens @sneridagh @davisagli as plone.app.discussion will soon be optional, any client should be prepared for whether or not they have the allow_discussion key in the response. So I think the failing test should be removed.

@Akshat2Jain please remove the test.

@Akshat2Jain
Copy link
Member Author

I mistakenly committed the changes without updating the branch, should I create a new branch within the repo?

@Akshat2Jain
Copy link
Member Author

@wesleybl , Can You help me with this?

@wesleybl
Copy link
Member

wesleybl commented Aug 1, 2023

@Akshat2Jain you can reset this commit:

b7c9acf

But if you think it's better, you can create a new branch and a new PR.

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.

Comments are displayed on the Plone Site when we set "No" to Allow discussion
5 participants