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

Command and REST API improvements #1263

Merged
merged 23 commits into from
Jan 10, 2018
Merged

Conversation

vboctor
Copy link
Member

@vboctor vboctor commented Jan 3, 2018

This PR restructured command data into multiple sub-arrays. These are:

  • query - typically used for url and query string parameters.
  • payload - used for the payload that is expected to be passed with a POST command.
  • options - provides the caller of the command the ability to pass options that control the command behavior.

The separation provides the advantage of having better similarity with REST API and protecting against a REST API payload specifying a value that it shouldn't, e.g. the issue_id that was provided before, or an option to a command.

The commands were also updated so as not to modify the passed in data. If they are to validate, normalize, and update passed in values, then such values are shared into command properties that are shared between validate() and process() methods.

The existing command was updated to follow the new model.

This PR also includes the following features:

  • 23774 Implement IssueNoteAddCommand to share code for adding notes
  • 23772 Support attachments when adding notes via REST API
  • 23773 Support time tracking when adding notes via REST API
  • 23775 Remove obsolete code that checks if PHP file info API is defined
  • 23776 Support adding attachments that were not uploaded via the browser
  • 23780 Return 429 status code for spam check errors
  • 23784 REST and SOAP API send two email notifications for mentioned users
  • 23785 Adding notes via SOAP and REST API with time tracking uses incorrect access check
  • 23786 Implement IssueNoteDeleteCommand for deleting notes

Instance of data accepting payload that is sometimes updated from the input from REST API.
It now works as follows:
- data[‘payload’] corresponds to REST API body.
- data[‘query’] corresponds to REST API URL path and query string params.
- data[‘options’] options to take into consideration when executing the command from the calling module.

If these elements are not set, they will be defaulted by the commands to an empty array.
- option() to access ‘options’.
- query() to access ‘query’.
- payload() To access ‘payload’.
- Differentiate invalid value from not found errors.
- Generate proper error when users is set to a non-array value.
- Use for REST API
- Use for Web UI
This is a step towards de-coupling attaching of files from the web UI post format.
A follow up will eventually allow attachments being included ias base64 content.
Following is a sample attribute to pass when creating a note:

```
“files”: [
  	{
  		"name": "test.txt",
  		"content": "VGhpcyBpcyBhIFRFU1QuDQpUaGlzIGlzIGEgVEVTVC4NClRoaXMgaXMgYSBURVNULg0KVGhpcyBpcyBhIFRFU1QuDQpUaGlzIGlzIGEgVEVTVC4="
  	}
  ]
```
"duration": "00:45",
},
"files": [
{
Copy link
Member Author

Choose a reason for hiding this comment

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

Will fix indentation.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

- Check that the other user has report issue note access.
- Attribute the note to the other user rather than the logged in user.
Make sure access checks are complete and are applied against the effective reporter.

- Private notes
- Attahcing files
- Time tracking

Update command sample data with comments and fixed indentation.
Base logic on reporter id rather than logged in user id.
- attr_value should only be used for reminders and doesn’t make sense to happen via SOAP API.
- note type can’t be TIME_TRACKING if note doesn’t have time tracking information.
- If note type not specified, but time tracking info is supplied, make sure type is set to TIME_TRACKING.
* @param string $p_file_path The file path.
* @return boolean|string The mime type or false on failure.
*/
function file_get_mime_type_for_content( $p_content ) {
Copy link
Member

Choose a reason for hiding this comment

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

The name of the previous function is file_get_mime_type.
Shouldn't the name of this function be content_get_mime_type ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope. file_ is the the prefix for all file_api. At the end of the day this is a file_ api that acts on file content rather than file path.

if( is_blank( $t_info_file ) ) {
$t_finfo = new finfo( FILEINFO_MIME );
} else {
$t_finfo = new finfo( FILEINFO_MIME, $t_info_file );
}
Copy link
Member

Choose a reason for hiding this comment

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

The code block starting with $t_info_file = ... is the same like the block in function file_get_mime_type

Instead of the whole block, use existing function finfo_get_if_available.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just pushed a refactored version of the code.

Get Issue and Add Note should use consistent time tracking formatting.
@vboctor vboctor merged commit 39ae82a into mantisbt:master Jan 10, 2018
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.

2 participants