2016-05-11 03:35:36 +02:00
|
|
|
class Scripts
|
2016-07-19 22:39:26 +02:00
|
|
|
def self.createUser(email = 'steve@jobs.com', password = 'custompassword', name = 'steve jobs')
|
2016-05-11 03:35:36 +02:00
|
|
|
response = request('/user/signup', {
|
2016-08-04 20:18:29 +02:00
|
|
|
:name => name,
|
|
|
|
:email => email,
|
|
|
|
:password => password
|
2016-05-11 03:35:36 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
if response['status'] === 'fail'
|
2016-12-29 06:04:35 +01:00
|
|
|
raise response['message']
|
2016-05-15 01:22:46 +02:00
|
|
|
end
|
2016-12-23 05:27:21 +01:00
|
|
|
userRow = $database.getRow('user', email, 'email')
|
2017-02-25 07:42:10 +01:00
|
|
|
request('/user/verify', {
|
2016-12-23 05:27:21 +01:00
|
|
|
:email => email,
|
|
|
|
:token => userRow['verification_token']
|
|
|
|
})
|
2016-05-11 03:35:36 +02:00
|
|
|
end
|
2016-08-04 20:18:29 +02:00
|
|
|
|
2018-03-12 23:31:54 +01:00
|
|
|
def self.createStaff(email, password, name, level='1')
|
|
|
|
departments = request('/system/get-settings', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
2019-02-14 23:43:22 +01:00
|
|
|
})['data']['departments']
|
2018-03-12 23:31:54 +01:00
|
|
|
departments = departments.collect { |x| x.id }
|
|
|
|
|
|
|
|
response = request('/staff/add', {
|
|
|
|
:name => name,
|
|
|
|
:email => email,
|
|
|
|
:password => password,
|
|
|
|
:level => level,
|
|
|
|
:departments => departments.to_string
|
|
|
|
})
|
|
|
|
|
|
|
|
if response['status'] === 'fail'
|
|
|
|
raise response['message']
|
|
|
|
end
|
|
|
|
end
|
2018-10-29 23:32:03 +01:00
|
|
|
def self.deleteStaff(staffId)
|
2018-10-29 15:32:31 +01:00
|
|
|
response = request('/staff/delete', {
|
2018-10-29 23:32:03 +01:00
|
|
|
staffId: staffId,
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
2018-10-29 15:32:31 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
if response['status'] === 'fail'
|
|
|
|
raise response['message']
|
|
|
|
end
|
|
|
|
end
|
2018-03-12 23:31:54 +01:00
|
|
|
|
2016-09-25 06:16:10 +02:00
|
|
|
def self.login(email = 'steve@jobs.com', password = 'custompassword', staff = false)
|
2016-08-04 20:18:29 +02:00
|
|
|
request('/user/logout')
|
|
|
|
response = request('/user/login', {
|
|
|
|
:email => email,
|
2016-09-25 06:16:10 +02:00
|
|
|
:password => password,
|
|
|
|
:staff => staff
|
2016-08-04 20:18:29 +02:00
|
|
|
})
|
|
|
|
|
2016-09-09 05:38:58 +02:00
|
|
|
if response['data'].any?
|
|
|
|
$csrf_userid = response['data']['userId']
|
|
|
|
$csrf_token = response['data']['token']
|
|
|
|
end
|
|
|
|
|
2016-08-04 20:18:29 +02:00
|
|
|
response['data']
|
|
|
|
end
|
2016-09-09 05:38:58 +02:00
|
|
|
|
2018-04-18 20:31:17 +02:00
|
|
|
def self.logout()
|
|
|
|
request('/user/logout')
|
|
|
|
end
|
|
|
|
|
2019-09-27 04:18:26 +02:00
|
|
|
def self.createTicket(title = 'Winter is coming',content = 'The north remembers', department = 1)
|
2016-09-09 05:38:58 +02:00
|
|
|
result = request('/ticket/create', {
|
2017-02-25 07:42:10 +01:00
|
|
|
title: title,
|
2019-06-27 03:04:56 +02:00
|
|
|
content: content,
|
2019-09-27 04:18:26 +02:00
|
|
|
departmentId: department,
|
2016-12-21 05:09:35 +01:00
|
|
|
language: 'en',
|
2016-09-09 05:38:58 +02:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
result['data']
|
|
|
|
end
|
2017-01-13 21:06:49 +01:00
|
|
|
|
2018-07-12 07:08:37 +02:00
|
|
|
def self.closeTicket(ticketNumber)
|
|
|
|
result = request('/ticket/close', {
|
|
|
|
ticketNumber:ticketNumber,
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
|
|
|
|
result['data']
|
|
|
|
end
|
|
|
|
|
2017-01-13 21:06:49 +01:00
|
|
|
def self.createAPIKey(name)
|
2017-02-25 07:42:10 +01:00
|
|
|
request('/system/add-api-key', {
|
2017-01-13 21:06:49 +01:00
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
name: name
|
|
|
|
})
|
|
|
|
end
|
2019-02-13 03:37:27 +01:00
|
|
|
|
|
|
|
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
|
2019-02-25 17:34:22 +01:00
|
|
|
def self.createTag(name, color)
|
|
|
|
request('/ticket/create-tag', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
name: name,
|
|
|
|
color: color
|
|
|
|
})
|
|
|
|
end
|
2019-07-02 01:38:34 +02:00
|
|
|
def self.assignTicket(ticketnumber)
|
|
|
|
request('/staff/assign-ticket', {
|
|
|
|
ticketNumber: ticketnumber,
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
end
|
2019-06-27 03:04:56 +02:00
|
|
|
def self.commentTicket(ticketnumber,content)
|
|
|
|
request('/ticket/comment', {
|
|
|
|
content: content,
|
|
|
|
ticketNumber: ticketnumber,
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
|
|
|
end
|
2016-05-11 03:35:36 +02:00
|
|
|
end
|