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
|
|
|
|
2021-10-09 00:04:25 +02:00
|
|
|
def self.inviteUser(email, name='genericName')
|
|
|
|
response = request('/user/invite', {
|
|
|
|
:name => name,
|
|
|
|
:email => email,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.inviteStaff(email, name='validName', level=1, profilePic='', departments: '[1]')
|
|
|
|
response = request('/staff/invite', {
|
|
|
|
:name => name,
|
|
|
|
:email => email,
|
|
|
|
:level => level,
|
2021-12-28 04:26:55 +01:00
|
|
|
:departments => departments.to_str
|
2021-10-09 00:04:25 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2019-10-31 20:13:04 +01:00
|
|
|
def self.createStaff(email, password, name, level='1') # WARNING: NOT USED ANYWHERE
|
2018-03-12 23:31:54 +01:00
|
|
|
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 }
|
|
|
|
|
2019-10-31 20:13:04 +01:00
|
|
|
response = request('/staff/invite', {
|
2018-03-12 23:31:54 +01:00
|
|
|
:name => name,
|
|
|
|
:email => email,
|
|
|
|
:level => level,
|
|
|
|
:departments => departments.to_string
|
|
|
|
})
|
|
|
|
|
2019-10-31 20:13:04 +01:00
|
|
|
recoverpassword = $database.getRow('recoverpassword', email, 'email')
|
|
|
|
|
|
|
|
response = request('/user/recover-password', {
|
|
|
|
email: email,
|
|
|
|
password: password,
|
|
|
|
token: recoverpassword['token']
|
|
|
|
})
|
|
|
|
|
2018-03-12 23:31:54 +01:00
|
|
|
if response['status'] === 'fail'
|
|
|
|
raise response['message']
|
|
|
|
end
|
|
|
|
end
|
2019-10-31 20:13:04 +01:00
|
|
|
|
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
|
|
|
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()
|
2021-11-05 21:06:08 +01:00
|
|
|
request('/user/logout', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token
|
|
|
|
})
|
2018-04-18 20:31:17 +02:00
|
|
|
end
|
|
|
|
|
2019-10-01 21:40:30 +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-10-01 21:40:30 +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
|
|
|
|
})
|
|
|
|
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
|
|
|
|
|
2020-10-14 20:08:14 +02:00
|
|
|
def self.createAPIKey(name, canCreateUsers=0, canCreateTickets=0, canCheckTickets=0, shouldReturnTicketNumber=0)
|
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,
|
2019-11-16 21:16:53 +01:00
|
|
|
name: name,
|
2020-10-14 20:08:14 +02:00
|
|
|
canCreateUsers: canCreateUsers,
|
|
|
|
canCreateTickets: canCreateTickets,
|
|
|
|
canCheckTickets: canCheckTickets,
|
|
|
|
shouldReturnTicketNumber: shouldReturnTicketNumber
|
2017-01-13 21:06:49 +01:00
|
|
|
})
|
|
|
|
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-10-31 20:13:04 +01:00
|
|
|
|
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-10-31 20:13:04 +01:00
|
|
|
|
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-10-31 20:13:04 +01:00
|
|
|
|
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
|
2020-06-15 21:27:45 +02:00
|
|
|
|
2021-12-17 18:10:57 +01:00
|
|
|
def self.createDepartment(nameDepartment, isPrivate = 0)
|
2020-06-15 21:27:45 +02:00
|
|
|
request('/system/add-department', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
2021-12-17 18:10:57 +01:00
|
|
|
name: nameDepartment,
|
|
|
|
private: isPrivate
|
2020-06-15 21:27:45 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.updateLockedDepartmentSetting(value = 0)
|
|
|
|
request('/system/edit-settings', {
|
|
|
|
csrf_userid: $csrf_userid,
|
|
|
|
csrf_token: $csrf_token,
|
|
|
|
"default-is-locked" => value
|
|
|
|
})
|
|
|
|
end
|
2016-05-11 03:35:36 +02:00
|
|
|
end
|