2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2016-09-07 06:47:31 +00:00
|
|
|
require 'browser_test_helper'
|
|
|
|
|
|
|
|
class AdminRoleTest < TestCase
|
2017-04-10 06:08:18 +00:00
|
|
|
def test_role_device
|
2016-09-07 06:47:31 +00:00
|
|
|
@browser = browser_instance
|
|
|
|
login(
|
2021-08-17 12:10:02 +00:00
|
|
|
username: 'admin@example.com',
|
2016-09-07 06:47:31 +00:00
|
|
|
password: 'test',
|
2018-12-19 17:31:51 +00:00
|
|
|
url: browser_url,
|
2016-09-07 06:47:31 +00:00
|
|
|
)
|
2021-07-16 13:29:38 +00:00
|
|
|
tasks_close_all
|
2016-09-07 06:47:31 +00:00
|
|
|
|
2021-09-20 10:47:05 +00:00
|
|
|
rand = SecureRandom.uuid
|
2020-09-30 09:07:01 +00:00
|
|
|
login = "agent-role-#{rand}"
|
|
|
|
firstname = "Role#{rand}"
|
|
|
|
lastname = "Module#{rand}"
|
|
|
|
email = "agent-role-#{rand}@example.com"
|
2016-09-07 06:47:31 +00:00
|
|
|
password = 'agentpw'
|
|
|
|
|
|
|
|
user_create(
|
|
|
|
data: {
|
2018-12-19 17:31:51 +00:00
|
|
|
login: login,
|
2016-09-07 06:47:31 +00:00
|
|
|
firstname: firstname,
|
2018-12-19 17:31:51 +00:00
|
|
|
lastname: lastname,
|
|
|
|
email: email,
|
|
|
|
password: password,
|
2016-09-07 06:47:31 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
name = "somerole#{rand}"
|
|
|
|
role_create(
|
|
|
|
data: {
|
|
|
|
name: name,
|
|
|
|
default_at_signup: false,
|
2018-12-19 17:31:51 +00:00
|
|
|
permission: [
|
2016-09-07 06:47:31 +00:00
|
|
|
'admin.group',
|
|
|
|
'user_preferences.device',
|
|
|
|
],
|
2018-12-19 17:31:51 +00:00
|
|
|
member: [login],
|
2016-09-07 06:47:31 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-07-16 13:29:38 +00:00
|
|
|
logout
|
2018-12-14 17:41:46 +00:00
|
|
|
# flanky
|
2016-09-07 06:47:31 +00:00
|
|
|
login(
|
|
|
|
username: email,
|
|
|
|
password: password,
|
2018-12-19 17:31:51 +00:00
|
|
|
url: browser_url,
|
2016-09-07 06:47:31 +00:00
|
|
|
)
|
2021-07-16 13:29:38 +00:00
|
|
|
tasks_close_all
|
2016-09-07 06:47:31 +00:00
|
|
|
click(css: 'a[href="#current_user"]')
|
|
|
|
click(css: 'a[href="#profile"]')
|
|
|
|
match(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Password',
|
|
|
|
)
|
|
|
|
match(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Language',
|
|
|
|
)
|
|
|
|
match_not(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Notifications',
|
|
|
|
)
|
|
|
|
match_not(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Calendar',
|
|
|
|
)
|
|
|
|
match_not(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Token Access',
|
|
|
|
)
|
|
|
|
match(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Devices',
|
|
|
|
)
|
|
|
|
|
2021-07-16 13:29:38 +00:00
|
|
|
logout
|
2016-09-07 06:47:31 +00:00
|
|
|
login(
|
2021-08-17 12:10:02 +00:00
|
|
|
username: 'admin@example.com',
|
2016-09-07 06:47:31 +00:00
|
|
|
password: 'test',
|
2018-12-19 17:31:51 +00:00
|
|
|
url: browser_url,
|
2016-09-07 06:47:31 +00:00
|
|
|
)
|
|
|
|
role_edit(
|
|
|
|
data: {
|
|
|
|
name: name,
|
|
|
|
active: false,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2021-07-16 13:29:38 +00:00
|
|
|
logout
|
2016-09-07 06:47:31 +00:00
|
|
|
login(
|
|
|
|
username: email,
|
|
|
|
password: password,
|
2018-12-19 17:31:51 +00:00
|
|
|
url: browser_url,
|
2016-09-07 06:47:31 +00:00
|
|
|
)
|
2021-07-16 13:29:38 +00:00
|
|
|
tasks_close_all
|
2016-09-07 06:47:31 +00:00
|
|
|
click(css: 'a[href="#current_user"]')
|
|
|
|
click(css: 'a[href="#profile"]')
|
|
|
|
match(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Password',
|
|
|
|
)
|
|
|
|
match(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Language',
|
|
|
|
)
|
|
|
|
match_not(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Notifications',
|
|
|
|
)
|
|
|
|
match_not(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Calendar',
|
|
|
|
)
|
|
|
|
match_not(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Token Access',
|
|
|
|
)
|
|
|
|
match_not(
|
2018-12-19 17:31:51 +00:00
|
|
|
css: '.content .NavBarProfile',
|
2016-09-07 06:47:31 +00:00
|
|
|
value: 'Devices',
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-04-10 06:08:18 +00:00
|
|
|
def test_role_admin_user
|
|
|
|
|
|
|
|
@browser = browser_instance
|
|
|
|
|
|
|
|
login(
|
|
|
|
username: 'agent1@example.com',
|
|
|
|
password: 'test',
|
2018-12-19 17:31:51 +00:00
|
|
|
url: browser_url,
|
2017-04-10 06:08:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# check if admin exists
|
|
|
|
exists_not(css: '[href="#manage"]')
|
2021-07-16 13:29:38 +00:00
|
|
|
logout
|
2017-04-10 06:08:18 +00:00
|
|
|
|
|
|
|
# add admin.user to agent role
|
|
|
|
login(
|
2021-08-17 12:10:02 +00:00
|
|
|
username: 'admin@example.com',
|
2017-04-10 06:08:18 +00:00
|
|
|
password: 'test',
|
2018-12-19 17:31:51 +00:00
|
|
|
url: browser_url,
|
2017-04-10 06:08:18 +00:00
|
|
|
)
|
2021-07-16 13:29:38 +00:00
|
|
|
tasks_close_all
|
2017-04-10 06:08:18 +00:00
|
|
|
|
|
|
|
role_edit(
|
|
|
|
data: {
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'Agent',
|
|
|
|
active: true,
|
2017-04-10 06:08:18 +00:00
|
|
|
permission: {
|
2018-12-19 17:31:51 +00:00
|
|
|
'admin.user' => true,
|
|
|
|
'chat.agent' => true,
|
|
|
|
'cti.agent' => true,
|
|
|
|
'ticket.agent' => true,
|
2017-04-10 06:08:18 +00:00
|
|
|
'user_preferences' => true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
2021-07-16 13:29:38 +00:00
|
|
|
logout
|
2017-04-10 06:08:18 +00:00
|
|
|
|
|
|
|
# check if admin exists
|
|
|
|
login(
|
|
|
|
username: 'agent1@example.com',
|
|
|
|
password: 'test',
|
2018-12-19 17:31:51 +00:00
|
|
|
url: browser_url,
|
2017-04-10 06:08:18 +00:00
|
|
|
)
|
2021-07-16 13:29:38 +00:00
|
|
|
tasks_close_all
|
2017-04-10 06:08:18 +00:00
|
|
|
|
|
|
|
# create user
|
2021-09-20 10:47:05 +00:00
|
|
|
random = SecureRandom.uuid
|
|
|
|
user_email = "admin.user.#{random}@example.com"
|
2017-04-10 06:08:18 +00:00
|
|
|
user_create(
|
|
|
|
data: {
|
2021-07-16 13:44:10 +00:00
|
|
|
# login: "some login #{random}",
|
2017-04-10 06:08:18 +00:00
|
|
|
firstname: "Admin.User Firstname #{random}",
|
|
|
|
lastname: "Admin.User Lastname #{random}",
|
|
|
|
email: user_email,
|
|
|
|
password: 'some-pass',
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
# create ticket for user
|
|
|
|
ticket_create(
|
|
|
|
data: {
|
|
|
|
customer: user_email,
|
2018-12-19 17:31:51 +00:00
|
|
|
group: 'Users',
|
|
|
|
title: 'some changes',
|
|
|
|
body: 'some body 123äöü - admin.user',
|
2017-04-10 06:08:18 +00:00
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
# revoke admin.user
|
2021-07-16 13:29:38 +00:00
|
|
|
logout
|
2017-04-10 06:08:18 +00:00
|
|
|
login(
|
2021-08-17 12:10:02 +00:00
|
|
|
username: 'admin@example.com',
|
2017-04-10 06:08:18 +00:00
|
|
|
password: 'test',
|
2018-12-19 17:31:51 +00:00
|
|
|
url: browser_url,
|
2017-04-10 06:08:18 +00:00
|
|
|
)
|
2021-07-16 13:29:38 +00:00
|
|
|
tasks_close_all
|
2017-04-10 06:08:18 +00:00
|
|
|
|
|
|
|
role_edit(
|
|
|
|
data: {
|
2018-12-19 17:31:51 +00:00
|
|
|
name: 'Agent',
|
|
|
|
active: true,
|
2017-04-10 06:08:18 +00:00
|
|
|
permission: {
|
2018-12-19 17:31:51 +00:00
|
|
|
'admin.user' => false,
|
|
|
|
'chat.agent' => true,
|
|
|
|
'cti.agent' => true,
|
|
|
|
'ticket.agent' => true,
|
2017-04-10 06:08:18 +00:00
|
|
|
'user_preferences' => true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
2021-07-16 13:29:38 +00:00
|
|
|
logout
|
2017-04-10 06:08:18 +00:00
|
|
|
|
|
|
|
login(
|
|
|
|
username: 'agent1@example.com',
|
|
|
|
password: 'test',
|
2018-12-19 17:31:51 +00:00
|
|
|
url: browser_url,
|
2017-04-10 06:08:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# check if admin exists
|
|
|
|
exists_not(css: '[href="#manage"]')
|
|
|
|
|
|
|
|
end
|
2018-11-09 13:06:21 +00:00
|
|
|
|
|
|
|
# regression test for issue #2332 - Role-Filter shows inactive Roles
|
|
|
|
def test_inactive_roles_do_not_show_in_role_filter
|
2021-09-20 10:47:05 +00:00
|
|
|
name = "some role #{SecureRandom.uuid}"
|
2018-11-09 13:06:21 +00:00
|
|
|
|
|
|
|
@browser = browser_instance
|
|
|
|
login(
|
2021-08-17 12:10:02 +00:00
|
|
|
username: 'admin@example.com',
|
2018-11-09 13:06:21 +00:00
|
|
|
password: 'test',
|
2018-12-19 17:31:51 +00:00
|
|
|
url: browser_url,
|
2018-11-09 13:06:21 +00:00
|
|
|
)
|
2021-07-16 13:29:38 +00:00
|
|
|
tasks_close_all
|
2018-11-09 13:06:21 +00:00
|
|
|
|
|
|
|
role_create(
|
|
|
|
data: {
|
|
|
|
name: name,
|
|
|
|
active: false
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
click(
|
2020-06-22 09:57:45 +00:00
|
|
|
css: '.content.active a[href="#manage/users"]',
|
2018-11-09 13:06:21 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# an inactive role should not appear in the role filter tabs
|
|
|
|
match_not(
|
|
|
|
css: '.content.active .userSearch',
|
|
|
|
value: name,
|
|
|
|
)
|
|
|
|
end
|
2016-09-07 06:47:31 +00:00
|
|
|
end
|