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

Create a method for returning a JSON response #2327

Closed
bschmalhofer opened this issue Jun 2, 2023 · 5 comments
Closed

Create a method for returning a JSON response #2327

bschmalhofer opened this issue Jun 2, 2023 · 5 comments
Assignees
Labels
good first issue Good for newcomers tidying Tidying of the code
Milestone

Comments

@bschmalhofer
Copy link
Contributor

Currently several frontend modules have a helper method that creates a JSON response. This is an indication that this is a commonly used functionality that warrants its own method in the layout object.

$ grep -r 'sub _ReturnJSON' Kernel/
Kernel/Modules/AdminSystemConfigurationUser.pm:sub _ReturnJSON {
Kernel/Modules/AgentReferenceSearch.pm:sub _ReturnJSON {
Kernel/Modules/AdminSystemConfigurationGroup.pm:sub _ReturnJSON {
Kernel/Modules/AgentContactWDSearch.pm:sub _ReturnJSON {
@bschmalhofer bschmalhofer self-assigned this Jun 2, 2023
@bschmalhofer bschmalhofer added the tidying Tidying of the code label Jun 2, 2023
@bschmalhofer bschmalhofer added this to the OTOBO 11.0 milestone Jun 2, 2023
@bschmalhofer bschmalhofer added the good first issue Good for newcomers label Jun 2, 2023
bschmalhofer added a commit that referenced this issue Jun 2, 2023
Use it for the ContactsWD dynamic field.
Use the method Attachment() internally.
@chaitanyak175
Copy link

Hey, I want to get involved in the opensource community how can I solve this issue. Please help as this will be my first open source contribution.

@bschmalhofer
Copy link
Contributor Author

Hi @chaitanyak175,

I'm not sure whether OTOBO is the best suited project for an overall open source contribution. As a first step I suggest that you do an installation of OTOBO so that you can see whether your contribution is working. Take a look at https://doc.otobo.org/manual/installation/10.1/en/content/installation-docker.html and see whether you can get started. Note that documentation fixes are welcome as well.

Best regards,
Bernhard

bschmalhofer added a commit that referenced this issue Jun 3, 2023
because FatalError() changes the control flow.
bschmalhofer added a commit that referenced this issue Jun 3, 2023
Add some comments. Write the check for Subactions as a guard clause.
Limit scope of some variables.
Try to make the control flow more obvious.
bschmalhofer added a commit that referenced this issue Jun 3, 2023
@bschmalhofer
Copy link
Contributor Author

bschmalhofer commented Jun 3, 2023

Hi @chaitanyak175,

I already have added the method JSONReply(). But there are still some things to do:

  • Refactor the remaining _ReturnJSON() helper methods to use JSONReply() instead
  • investigate whether other frontend modules can make use of JSONReply()

No need to limit the passed in data to Hashref, Arrayref, and String. Cpanel::JSON::XS already croaks.

bschmalhofer added a commit that referenced this issue Jun 3, 2023
$Param{Data} already is a reference
bschmalhofer added a commit that referenced this issue Jun 3, 2023
@bschmalhofer
Copy link
Contributor Author

Let's do this after #399 is merged into rel-11_0. This reduced the number of variants that must be tested.

bschmalhofer added a commit that referenced this issue Jun 9, 2023
Thus the _ReturnJSON helper subs can be removed.
bschmalhofer added a commit that referenced this issue Jun 9, 2023
For example the JSON that encodes the number 0.
bschmalhofer added a commit that referenced this issue Jun 9, 2023
@bschmalhofer
Copy link
Contributor Author

A lot more frontend modules could be converted. But there is no good reason to do that now. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers tidying Tidying of the code
Projects
None yet
Development

No branches or pull requests

2 participants