mirror of
https://github.com/opensupports/opensupports.git
synced 2025-09-26 11:29:05 +02:00
commit
9a116c5c29
@ -41,16 +41,20 @@ class DeleteCustomFieldController extends Controller {
|
|||||||
public function handler() {
|
public function handler() {
|
||||||
$customField = Customfield::getDataStore(Controller::request('id'));
|
$customField = Customfield::getDataStore(Controller::request('id'));
|
||||||
|
|
||||||
foreach(Users::getAll() as $user) {
|
foreach(User::getAll() as $user) {
|
||||||
$customFieldValueList = $user->xownCustomfieldvalueList || [];
|
$customFieldValueList = $user->xownCustomfieldvalueList ? $user->xownCustomfieldvalueList : [];
|
||||||
|
|
||||||
foreach($customFieldValueList as $customFieldValue) {
|
foreach($customFieldValueList as $customFieldValue) {
|
||||||
if($customFieldValue->customfield->id == $customField->id) {
|
if($customFieldValue->customfield->id == $customField->id) {
|
||||||
$user->xownCustomfieldvalueList->remove($customFieldValue);
|
$user->xownCustomfieldvalueList->remove($customFieldValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$user->store();
|
||||||
}
|
}
|
||||||
|
|
||||||
$customField->delete();
|
$customField->delete();
|
||||||
|
|
||||||
|
Response::respondSuccess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class EmailPollingController extends Controller {
|
|||||||
|
|
||||||
$errors = [];
|
$errors = [];
|
||||||
$emails = $this->getLastEmails();
|
$emails = $this->getLastEmails();
|
||||||
/*
|
|
||||||
$session = Session::getInstance();
|
$session = Session::getInstance();
|
||||||
$oldSession = [
|
$oldSession = [
|
||||||
'userId' => $session->getUserId(),
|
'userId' => $session->getUserId(),
|
||||||
@ -70,9 +70,9 @@ class EmailPollingController extends Controller {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
/*
|
||||||
if($email->getAttachement()) {
|
if($email->getAttachment()) {
|
||||||
$attachment = $email->getAttachement();
|
$attachment = $email->getAttachment();
|
||||||
$_FILES['file'] = [
|
$_FILES['file'] = [
|
||||||
'name' => $attachment->name,
|
'name' => $attachment->name,
|
||||||
'type' => mime_content_type($attachment->filePath),
|
'type' => mime_content_type($attachment->filePath),
|
||||||
@ -81,6 +81,7 @@ class EmailPollingController extends Controller {
|
|||||||
'size' => filesize($attachment->filePath),
|
'size' => filesize($attachment->filePath),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if($email->isReply()) {
|
if($email->isReply()) {
|
||||||
@ -113,7 +114,7 @@ class EmailPollingController extends Controller {
|
|||||||
Response::respondError(ERRORS::EMAIL_POLLING, null, $errors);
|
Response::respondError(ERRORS::EMAIL_POLLING, null, $errors);
|
||||||
} else {
|
} else {
|
||||||
Response::respondSuccess();
|
Response::respondSuccess();
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLastEmails() {
|
public function getLastEmails() {
|
||||||
@ -124,15 +125,19 @@ class EmailPollingController extends Controller {
|
|||||||
foreach($mailsIds as $mailId) {
|
foreach($mailsIds as $mailId) {
|
||||||
$mail = $this->mailbox->getMail($mailId);
|
$mail = $this->mailbox->getMail($mailId);
|
||||||
$mailHeader = $this->mailbox->getMailHeader($mailId);
|
$mailHeader = $this->mailbox->getMailHeader($mailId);
|
||||||
$mailAttachment = count($mail->getAttachments()) ? $mail->getAttachments()[0] : null;
|
// $mailAttachment = count($mail->getAttachments()) ? current($mail->getAttachments()) : null;
|
||||||
|
|
||||||
$emails[] = new Email([
|
$emails[] = new Email([
|
||||||
'fromAddress' => $mailHeader->fromAddress,
|
'fromAddress' => $mailHeader->fromAddress,
|
||||||
'fromName' => $mailHeader->fromName,
|
'fromName' => $mailHeader->fromName,
|
||||||
'subject' => $mailHeader->subject,
|
'subject' => $mailHeader->subject,
|
||||||
'content' => $mail->textPlain,
|
'content' => $mail->textPlain,
|
||||||
'file' => $mailAttachment,
|
'file' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
foreach($mail->getAttachments() as $attachment) {
|
||||||
|
unlink($attachment->filePath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $emails;
|
return $emails;
|
||||||
|
@ -134,7 +134,6 @@ abstract class Controller {
|
|||||||
$fileUploader->setMaxSize($maxSize);
|
$fileUploader->setMaxSize($maxSize);
|
||||||
|
|
||||||
if($fileUploader->upload('file')) {
|
if($fileUploader->upload('file')) {
|
||||||
|
|
||||||
return $fileUploader;
|
return $fileUploader;
|
||||||
} else {
|
} else {
|
||||||
throw new RequestException(ERRORS::INVALID_FILE);
|
throw new RequestException(ERRORS::INVALID_FILE);
|
||||||
|
@ -40,6 +40,9 @@ class DataStoreId extends AbstractRule {
|
|||||||
case 'article':
|
case 'article':
|
||||||
$dataStore = \Article::getDataStore($dataStoreId);
|
$dataStore = \Article::getDataStore($dataStoreId);
|
||||||
break;
|
break;
|
||||||
|
case 'customfield':
|
||||||
|
$dataStore = \Customfield::getDataStore($dataStoreId);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return !$dataStore->isNull();
|
return !$dataStore->isNull();
|
||||||
@ -53,7 +56,8 @@ class DataStoreId extends AbstractRule {
|
|||||||
'department',
|
'department',
|
||||||
'customresponse',
|
'customresponse',
|
||||||
'topic',
|
'topic',
|
||||||
'article'
|
'article',
|
||||||
|
'customfield'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -62,5 +62,6 @@ require './system/delete-api-key.rb'
|
|||||||
require './system/get-api-keys.rb'
|
require './system/get-api-keys.rb'
|
||||||
require './system/file-upload-download.rb'
|
require './system/file-upload-download.rb'
|
||||||
require './system/csv-import.rb'
|
require './system/csv-import.rb'
|
||||||
|
require './system/custom-fields.rb'
|
||||||
require './system/disable-user-system.rb'
|
require './system/disable-user-system.rb'
|
||||||
require './system/get-stats.rb'
|
require './system/get-stats.rb'
|
||||||
|
@ -141,7 +141,7 @@ end
|
|||||||
$database = Database.new
|
$database = Database.new
|
||||||
|
|
||||||
# $mail_server.clear_mails
|
# $mail_server.clear_mails
|
||||||
# $mail_server.send_mail('suppport message 1', 'texttexttext tex')
|
# $mail_server.send_mail('support message 1', 'texttexttext tex')
|
||||||
# $mail_server.check
|
# $mail_server.check
|
||||||
|
|
||||||
$staff = {
|
$staff = {
|
||||||
|
@ -97,4 +97,14 @@ class Scripts
|
|||||||
name: name
|
name: name
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.createTextCustomField(name,description)
|
||||||
|
request('/system/add-custom-field', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
name: name,
|
||||||
|
type: 'text',
|
||||||
|
description: description
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
251
tests/system/custom-fields.rb
Normal file
251
tests/system/custom-fields.rb
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
describe 'Custom fields' do
|
||||||
|
request('/user/logout')
|
||||||
|
Scripts.login($staff[:email], $staff[:password], true)
|
||||||
|
|
||||||
|
describe '/system/add-custom-field' do
|
||||||
|
|
||||||
|
it 'should fail if the name is to short ' do
|
||||||
|
result = request('/system/add-custom-field', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
name: 'A',
|
||||||
|
type: 'text',
|
||||||
|
description: 'custom field description',
|
||||||
|
options: nil
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('INVALID_NAME')
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail if the name is to long' do
|
||||||
|
long_text = ''
|
||||||
|
101.times {long_text << 'A'}
|
||||||
|
|
||||||
|
result = request('/system/add-custom-field', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
name: long_text,
|
||||||
|
type: 'text',
|
||||||
|
description: 'custom field description',
|
||||||
|
options: nil
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('INVALID_NAME')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail if the type is not one of text or select'do
|
||||||
|
result = request('/system/add-custom-field', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
name: 'name of custom field',
|
||||||
|
type: 'tex',
|
||||||
|
description: 'custom field description'
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('INVALID_CUSTOM_FIELD_TYPE')
|
||||||
|
|
||||||
|
result = request('/system/add-custom-field', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
name: 'name of custom field',
|
||||||
|
type: 'selec',
|
||||||
|
description: 'custom field description'
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('INVALID_CUSTOM_FIELD_TYPE')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail if the option is invalid' do
|
||||||
|
result = request('/system/add-custom-field', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
name: 'name of custom field',
|
||||||
|
type: 'select',
|
||||||
|
description: 'custom field description',
|
||||||
|
options: 'json'
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('INVALID_CUSTOM_FIELD_OPTIONS')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should create name of select customfield' do
|
||||||
|
result = request('/system/add-custom-field', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
name: 'mockselectfield',
|
||||||
|
type: 'select',
|
||||||
|
description: 'custom field description',
|
||||||
|
options: '["option1","option2","option3"]'
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
|
custom_field_row = $database.getRow('customfield', 'mockselectfield', 'name')
|
||||||
|
custom_field_row_id = custom_field_row['id']
|
||||||
|
|
||||||
|
(custom_field_row['name']).should.equal('mockselectfield')
|
||||||
|
(custom_field_row['type']).should.equal('select')
|
||||||
|
(custom_field_row['description']).should.equal('custom field description')
|
||||||
|
|
||||||
|
($database.getRow('customfieldoption', 'option1', 'name')['customfield_id']).should.equal(custom_field_row_id)
|
||||||
|
($database.getRow('customfieldoption', 'option2', 'name')['customfield_id']).should.equal(custom_field_row_id)
|
||||||
|
($database.getRow('customfieldoption', 'option3', 'name')['customfield_id']).should.equal(custom_field_row_id)
|
||||||
|
|
||||||
|
quantity_of_options = $database.query("SELECT COUNT(*) as qt FROM customfieldoption WHERE customfield_id='#{custom_field_row_id}'").fetch_hash['qt']
|
||||||
|
(quantity_of_options).should.equal("3")
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail if field name already exists' do
|
||||||
|
result = request('/system/add-custom-field', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
name: 'mockselectfield',
|
||||||
|
type: 'select',
|
||||||
|
description: 'custom field description',
|
||||||
|
options: '["option1","option2","option3"]'
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('CUSTOM_FIELD_ALREADY_EXISTS')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '/system/get-custom-fields' do
|
||||||
|
|
||||||
|
it 'should success and shows all custom fields' do
|
||||||
|
Scripts.createTextCustomField('mocktextfield1','description number 1')
|
||||||
|
Scripts.createTextCustomField('mocktextfield2','description number 2')
|
||||||
|
Scripts.createTextCustomField('mocktextfield3',nil)
|
||||||
|
|
||||||
|
result = request('/system/get-custom-fields', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
(result['data'].size).should.equal(4)
|
||||||
|
|
||||||
|
result['data'][0]['name'].should.equal('mockselectfield')
|
||||||
|
result['data'][0]['type'].should.equal('select')
|
||||||
|
result['data'][0]['description'].should.equal('custom field description')
|
||||||
|
result['data'][0]['options'].should.equal([
|
||||||
|
{'id' => '1', 'name'=> 'option1'},
|
||||||
|
{'id' => '2', 'name'=> 'option2'},
|
||||||
|
{'id' => '3', 'name'=> 'option3'},
|
||||||
|
])
|
||||||
|
result['data'][1]['name'].should.equal('mocktextfield1')
|
||||||
|
result['data'][1]['type'].should.equal('text')
|
||||||
|
result['data'][1]['description'].should.equal('description number 1')
|
||||||
|
result['data'][2]['name'].should.equal('mocktextfield2')
|
||||||
|
result['data'][2]['type'].should.equal('text')
|
||||||
|
result['data'][2]['description'].should.equal('description number 2')
|
||||||
|
result['data'][3]['name'].should.equal('mocktextfield3')
|
||||||
|
result['data'][3]['type'].should.equal('text')
|
||||||
|
result['data'][3]['description'].should.equal('')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
describe '/user/edit-custom-fields' do
|
||||||
|
|
||||||
|
it 'should add custom field values to user' do
|
||||||
|
last_user_id = $database.getLastRow('user')['id']
|
||||||
|
result = request('/user/edit-custom-fields', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
userId: last_user_id,
|
||||||
|
customfield_mockselectfield: 'option2',
|
||||||
|
customfield_mocktextfield3: 'mockvalue',
|
||||||
|
})
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
|
result = request('/user/get-user', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
userId: last_user_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
(result['data']['customfields'][0]['customfield']).should.equal('mockselectfield')
|
||||||
|
(result['data']['customfields'][0]['value']).should.equal('option2')
|
||||||
|
(result['data']['customfields'][0]['customfieldoption']['id']).should.equal('2')
|
||||||
|
(result['data']['customfields'][0]['customfieldoption']['name']).should.equal('option2')
|
||||||
|
|
||||||
|
(result['data']['customfields'][1]['customfield']).should.equal('mocktextfield3')
|
||||||
|
(result['data']['customfields'][1]['value']).should.equal('mockvalue')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should allow changes' do
|
||||||
|
last_user_id = $database.getLastRow('user')['id']
|
||||||
|
result = request('/user/edit-custom-fields', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
userId: last_user_id,
|
||||||
|
customfield_mockselectfield: 'option3',
|
||||||
|
customfield_mocktextfield3: 'mockvalue2',
|
||||||
|
})
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
|
result = request('/user/get-user', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
userId: last_user_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
(result['data']['customfields'].size).should.equal(2)
|
||||||
|
(result['data']['customfields'][0]['customfield']).should.equal('mockselectfield')
|
||||||
|
(result['data']['customfields'][0]['value']).should.equal('option3')
|
||||||
|
(result['data']['customfields'][0]['customfieldoption']['id']).should.equal('3')
|
||||||
|
(result['data']['customfields'][0]['customfieldoption']['name']).should.equal('option3')
|
||||||
|
|
||||||
|
(result['data']['customfields'][1]['customfield']).should.equal('mocktextfield3')
|
||||||
|
(result['data']['customfields'][1]['value']).should.equal('mockvalue2')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '/system/delete-custom-field' do
|
||||||
|
|
||||||
|
it 'should fail if is an invalid custom field ' do
|
||||||
|
result = request('/system/delete-custom-field', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
id: 100
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('fail')
|
||||||
|
(result['message']).should.equal('INVALID_CUSTOM_FIELD')
|
||||||
|
|
||||||
|
end
|
||||||
|
it 'should success if everything is ok' do
|
||||||
|
result = request('/system/delete-custom-field', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
id: 1
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
|
||||||
|
custom_field_row = $database.getRow('customfield', 1, 'id')
|
||||||
|
(custom_field_row).should.equal(nil)
|
||||||
|
|
||||||
|
last_user_id = $database.getLastRow('user')['id']
|
||||||
|
result = request('/user/get-user', {
|
||||||
|
csrf_userid: $csrf_userid,
|
||||||
|
csrf_token: $csrf_token,
|
||||||
|
userId: last_user_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
(result['status']).should.equal('success')
|
||||||
|
(result['data']['customfields'].size).should.equal(1)
|
||||||
|
(result['data']['customfields'][0]['customfield']).should.equal('mocktextfield3')
|
||||||
|
(result['data']['customfields'][0]['value']).should.equal('mockvalue2')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user