Skip to content

Commit

Permalink
Fix #12795 : Handle the 'user_id' property of attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
rombert committed Apr 11, 2011
1 parent 13bc745 commit c181cc1
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 9 deletions.
6 changes: 4 additions & 2 deletions api/soap/mantisconnect.php
Expand Up @@ -122,7 +122,8 @@
'size' => array( 'name' => 'size', 'type' => 'xsd:integer', 'minOccurs' => '0'),
'content_type' => array( 'name' => 'content_type', 'type' => 'xsd:string', 'minOccurs' => '0'),
'date_submitted' => array( 'name' => 'date_submitted', 'type' => 'xsd:dateTime', 'minOccurs' => '0'),
'download_url' => array( 'name' => 'download_url', 'type' => 'xsd:anyURI', 'minOccurs' => '0')
'download_url' => array( 'name' => 'download_url', 'type' => 'xsd:anyURI', 'minOccurs' => '0'),
'user_id' => array( 'name' => 'user_id', 'type' => 'xsd:integer', 'minOccurs' => '0')
)
);

Expand Down Expand Up @@ -156,7 +157,8 @@
'size' => array( 'name' => 'size', 'type' => 'xsd:integer', 'minOccurs' => '0'),
'content_type' => array( 'name' => 'content_type', 'type' => 'xsd:string', 'minOccurs' => '0'),
'date_submitted' => array( 'name' => 'date_submitted', 'type' => 'xsd:dateTime', 'minOccurs' => '0'),
'download_url' => array( 'name' => 'download_url', 'type' => 'xsd:anyURI', 'minOccurs' => '0')
'download_url' => array( 'name' => 'download_url', 'type' => 'xsd:anyURI', 'minOccurs' => '0'),
'user_id' => array( 'name' => 'user_id', 'type' => 'xsd:integer', 'minOccurs' => '0')
)
);

Expand Down
13 changes: 10 additions & 3 deletions api/soap/mc_file_api.php
Expand Up @@ -32,7 +32,7 @@ function mci_file_write_local( $p_diskfile, $p_content ) {
fclose( $t_handle );
}

function mci_file_add( $p_id, $p_name, $p_content, $p_file_type, $p_table, $p_title = '', $p_desc = '' ) {
function mci_file_add( $p_id, $p_name, $p_content, $p_file_type, $p_table, $p_title = '', $p_desc = '', $p_user_id = null ) {
if( !file_type_check( $p_name ) ) {
return new soap_fault( 'Client', '', 'File type not allowed.' );
}
Expand Down Expand Up @@ -60,6 +60,13 @@ function mci_file_add( $p_id, $p_name, $p_content, $p_file_type, $p_table, $p_ti
$c_file_type = db_prepare_string( $p_file_type );
$c_title = db_prepare_string( $p_title );
$c_desc = db_prepare_string( $p_desc );

if( $p_user_id === null ) {
$c_user_id = auth_get_current_user_id();
} else {
$c_user_id = (int)$p_user_id;
}


if( $t_project_id == ALL_PROJECTS ) {
$t_file_path = config_get( 'absolute_path_default_upload_folder' );
Expand Down Expand Up @@ -114,9 +121,9 @@ function mci_file_add( $p_id, $p_name, $p_content, $p_file_type, $p_table, $p_ti
$t_file_table = db_get_table( $p_table . '_file' );
$c_id = ( 'bug' == $p_table ) ? $c_issue_id : $c_project_id;
$query = "INSERT INTO $t_file_table
(" . $p_table . "_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content)
(" . $p_table . "_id, title, description, diskfile, filename, folder, filesize, file_type, date_added, content, user_id)
VALUES
($c_id, '$c_title', '$c_desc', '$c_disk_file_name', '$c_new_file_name', '$c_file_path', $c_file_size, '$c_file_type', '" . db_now() . "', $c_content)";
($c_id, '$c_title', '$c_desc', '$c_disk_file_name', '$c_new_file_name', '$c_file_path', $c_file_size, '$c_file_type', '" . db_now() . "', $c_content, $c_user_id)";
db_query( $query );

# get attachment id
Expand Down
1 change: 1 addition & 0 deletions api/soap/mc_issue_api.php
Expand Up @@ -248,6 +248,7 @@ function mci_issue_get_attachments( $p_issue_id ) {
$t_attachment['content_type'] = $t_attachment_row['file_type'];
$t_attachment['date_submitted'] = timestamp_to_iso8601( $t_attachment_row['date_added'] );
$t_attachment['download_url'] = mci_get_mantis_path() . 'file_download.php?file_id=' . $t_attachment_row['id'] . '&type=bug';
$t_attachment['user_id'] = $t_attachment_row['user_id'];
$t_result[] = $t_attachment;
}

Expand Down
2 changes: 1 addition & 1 deletion api/soap/mc_issue_attachment_api.php
Expand Up @@ -51,7 +51,7 @@ function mc_issue_attachment_add( $p_username, $p_password, $p_issue_id, $p_name
if( !access_has_bug_level( config_get( 'upload_bug_file_threshold' ), $p_issue_id, $t_user_id ) ) {
return mci_soap_fault_access_denied( $t_user_id );
}
return mci_file_add( $p_issue_id, $p_name, $p_content, $p_file_type, 'bug' );
return mci_file_add( $p_issue_id, $p_name, $p_content, $p_file_type, 'bug', '', '', $t_user_id );
}

/**
Expand Down
3 changes: 2 additions & 1 deletion api/soap/mc_project_api.php
Expand Up @@ -583,7 +583,7 @@ function mc_project_get_attachments( $p_username, $p_password, $p_project_id ) {
$t_access_clause = ">= $t_reqd_access ";
}

$query = "SELECT pft.id, pft.project_id, pft.filename, pft.file_type, pft.filesize, pft.title, pft.description, pft.date_added
$query = "SELECT pft.id, pft.project_id, pft.filename, pft.file_type, pft.filesize, pft.title, pft.description, pft.date_added, pft.user_id
FROM $t_project_file_table pft
LEFT JOIN $t_project_table pt ON pft.project_id = pt.id
LEFT JOIN $t_project_user_list_table pult
Expand All @@ -610,6 +610,7 @@ function mc_project_get_attachments( $p_username, $p_password, $p_project_id ) {
$t_attachment['content_type'] = $row['file_type'];
$t_attachment['date_submitted'] = timestamp_to_iso8601( $row['date_added'] );
$t_attachment['download_url'] = mci_get_mantis_path() . 'file_download.php?file_id=' . $row['id'] . '&type=doc';
$t_attachment['user_id'] = $row['user_id'];
$t_result[] = $t_attachment;
}

Expand Down
2 changes: 1 addition & 1 deletion api/soap/mc_project_attachment_api.php
Expand Up @@ -58,7 +58,7 @@ function mc_project_attachment_add( $p_username, $p_password, $p_project_id, $p_
if( is_blank( $p_title ) ) {
return new soap_fault( 'Client', '', 'Title must not be empty.' );
}
return mci_file_add( $p_project_id, $p_name, $p_content, $p_file_type, 'project', $p_title, $p_description );
return mci_file_add( $p_project_id, $p_name, $p_content, $p_file_type, 'project', $p_title, $p_description, $t_user_id );
}

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/soap/AttachmentTest.php
Expand Up @@ -74,6 +74,7 @@ public function testAttachmentIsAdded() {
$this->assertEquals( 1, count( $issue->attachments ), 'count($issue->attachments)' );
$this->assertEquals( $attachmentContents, base64_decode( $attachment ), '$attachmentContents' );
$this->assertEquals( $this->mantisPath.'file_download.php?file_id='.$issue->attachments[0]->id.'&type=bug', $issue->attachments[0]->download_url);
$this->assertEquals( $this->userId, $issue->attachments[0]->user_id);
}


Expand Down Expand Up @@ -127,6 +128,13 @@ public function testProjectAttachmentIsAdded() {
$attachmentId);

$this->assertEquals( $attachmentContents, base64_decode( $attachment ), '$attachmentContents' );

$attachments = $this->client->mc_project_get_attachments( $this->userName, $this->password, $this->getProjectId() );
$this->assertEquals( 1, count( $attachments ) );

$attachment = $attachments[0];
$this->assertEquals($this->userId, $attachment->user_id);
$this->assertEquals('description', $attachment->description);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/soap/IssueAddTest.php
Expand Up @@ -442,7 +442,7 @@ public function testGetBiggestId() {
$firstIssueId = $this->client->mc_issue_add( $this->userName, $this->password, $this->getIssueToAdd( 'IssueAddTest.testGetBiggestId1'));
$this->deleteAfterRun( $firstIssueId );

$secondIssueId = $this->client->mc_issue_add( $this->userName, $this->password, $this->getIssueToAdd( 'IssueAddTest.testGetBiggestId1'));
$secondIssueId = $this->client->mc_issue_add( $this->userName, $this->password, $this->getIssueToAdd( 'IssueAddTest.testGetBiggestId2'));
$this->deleteAfterRun( $secondIssueId );

$firstIssue = $this->client->mc_issue_get( $this->userName, $this->password, $firstIssueId );
Expand Down

0 comments on commit c181cc1

Please sign in to comment.