mirror of
https://github.com/itflow-org/itflow
synced 2026-12-04 01:59:00 +00:00
API / service accounts take no seat on the agent user limit, the managed instance's or config.php's: getActiveAgentUserCount() leaves them out, so the seats taken, the limit checks and the report to the manager do too; one can be added, enabled, restored or bulk enabled when every seat is taken, New User stays open with the window saying so, and turning an active one back into an agent who signs in needs a free seat (serviceAccountLeavingNeedsSeat()); 26.12.5 changelog
This commit is contained in:
14
CHANGELOG.md
14
CHANGELOG.md
@@ -2,6 +2,20 @@
|
||||
|
||||
This file documents all notable changes made to ITFlow.
|
||||
|
||||
## [26.12.5]
|
||||
|
||||
### Upgrading to 26.12.5
|
||||
|
||||
Update from Maintenance > Update as usual. There are no database changes.
|
||||
|
||||
### New Features & Updates
|
||||
|
||||
- An API / service account no longer takes a seat on the agent user limit - the one your hosting provider sets, or one set for your installation. Nobody signs in as it: it's the login an integration's API keys act as. You can add one, enable one or restore one when every seat is taken, and Admin > Users shows the seats without them. Turning one back into an agent who signs in takes a seat, so there has to be one free. A hosted instance's manager sees it the same way: its seats taken leave API accounts out, and its list of agents marks them.
|
||||
|
||||
### Developer Updates
|
||||
|
||||
- `getActiveAgentUserCount()` (`functions/app.php`) leaves out `users.user_service_account = 1` with `serviceAccountsOutSql()`, so `getAgentSeatsTaken()`, `agentUserLimitReached()` and the managed report's `agents.active` do too (the report's list still carries them, with `service` set). `admin/post/users.php` skips `agentUserLimitReached()` for an API / service account in `add_user`, `activate_user`, `restore_user` and `bulk_activate_users`, and `edit_user` refuses turning an active one into an agent at the limit before changing anything (`serviceAccountLeavingNeedsSeat()`, `functions/service_account.php`). Admin > Users keeps New User open at the limit when service accounts are available, and the New User window says one can still be added.
|
||||
|
||||
## [26.12.4]
|
||||
|
||||
### Upgrading to 26.12.4
|
||||
|
||||
@@ -352,7 +352,7 @@ if ($error_count > 0) {
|
||||
<td class="ps-3">
|
||||
<div class="fw-semibold"><?= escapeHtml((string) ($agent['name'] ?? '')) ?>
|
||||
<?php if ($invited) { ?><span class="badge rounded-pill bg-info-subtle text-info-emphasis border border-info-subtle fw-normal ms-1">Invited</span><?php } ?>
|
||||
<?php if (!empty($agent['service'])) { ?><span class="badge rounded-pill bg-secondary-subtle text-secondary-emphasis border border-secondary-subtle fw-normal ms-1">API account</span><?php } ?>
|
||||
<?php if (!empty($agent['service'])) { ?><span class="badge rounded-pill bg-secondary-subtle text-secondary-emphasis border border-secondary-subtle fw-normal ms-1" title="A login only for API keys - it can't sign in, and takes no seat">API account</span><?php } ?>
|
||||
</div>
|
||||
<div class="text-body-secondary text-break"><?= escapeHtml((string) ($agent['email'] ?? '')) ?></div>
|
||||
</td>
|
||||
|
||||
@@ -27,7 +27,7 @@ ob_start();
|
||||
|
||||
<div class="modal-body">
|
||||
<?php if (agentUserLimitReached()) { ?>
|
||||
<div class="alert alert-danger small"><?= agentUserLimitMessage() ?></div>
|
||||
<div class="alert alert-danger small" data-user-limit><?= agentUserLimitMessage() ?><?= serviceAccountsReady() ? ' You can still add an API / service account - it takes no seat.' : '' ?></div>
|
||||
<?php } ?>
|
||||
<?php require 'user_form.php'; ?>
|
||||
</div>
|
||||
|
||||
@@ -189,7 +189,7 @@ $value = function ($key) use ($form) {
|
||||
<input class="form-check-input" type="checkbox" role="switch" name="service_account" value="1" id="<?= $form_id ?>ServiceAccount" <?= $form_service ? 'checked' : '' ?>>
|
||||
<label class="form-check-label fw-semibold" for="<?= $form_id ?>ServiceAccount"><i class="fas fa-fw fa-plug text-body-secondary me-1"></i>API / service account</label>
|
||||
<div class="form-text mt-0">
|
||||
For a login that API keys act as, for an integration. It keeps its role, so its keys work, but it's left out of the calendar, every assign picker, the reports and the other agent lists, gets no notifications, and can't sign in to ITFlow.
|
||||
For a login that API keys act as, for an integration. It keeps its role, so its keys work, but it takes no seat on the agent user limit, it's left out of the calendar, every assign picker, the reports and the other agent lists, gets no notifications, and can't sign in to ITFlow.
|
||||
<?= $is_new ? 'Set a password for it - it isn\'t invited.' : '' ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -34,7 +34,7 @@ ob_start();
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (agentUserLimitReached()) { ?>
|
||||
<?php if (agentUserLimitReached() && !serviceAccountIs($user_id)) { ?>
|
||||
<div class="alert alert-danger small"><?= agentUserLimitMessage() ?></div>
|
||||
<?php } ?>
|
||||
<?php if ($email_taken) { ?>
|
||||
|
||||
@@ -52,9 +52,11 @@ if (isset($_POST['add_user'])) {
|
||||
redirect();
|
||||
}
|
||||
|
||||
// An invite waiting for them holds a seat already - it is this one
|
||||
// An invite waiting for them holds a seat already - it is this one. An API / service account
|
||||
// takes none (functions/service_account.php)
|
||||
$open = userInviteFor($email);
|
||||
if (agentUserLimitReached($open && userInviteState($open) === 'pending' ? intval($open['invite_id']) : 0)) {
|
||||
$service_new = !empty($_POST['service_account']) && serviceAccountsReady();
|
||||
if (!$service_new && agentUserLimitReached($open && userInviteState($open) === 'pending' ? intval($open['invite_id']) : 0)) {
|
||||
flashAlert(agentUserLimitMessage(), 'error');
|
||||
redirect();
|
||||
}
|
||||
@@ -268,6 +270,11 @@ if (isset($_POST['edit_user'])) {
|
||||
if (intval($row['role_is_admin']) && !intval($role['role_is_admin'])) {
|
||||
userGuardLastAdmin($row, 'a role without admin');
|
||||
}
|
||||
// An API / service account takes no seat - an agent who signs in does (functions/service_account.php)
|
||||
if (serviceAccountLeavingNeedsSeat($row, $_POST)) {
|
||||
flashAlert('<strong>' . escapeHtml($row['user_name']) . '</strong> is still an API / service account, which takes no seat - as an agent who signs in it would need one. ' . agentUserLimitMessage(), 'error');
|
||||
redirect();
|
||||
}
|
||||
|
||||
mysqli_query($mysqli, "UPDATE users SET user_name = '" . escapeSql($name) . "', user_email = '" . escapeSql($email) . "', user_role_id = " . intval($role['role_id']) . " WHERE user_id = $user_id");
|
||||
$force_mfa = !empty($_POST['force_mfa']) ? 1 : 0;
|
||||
@@ -332,8 +339,9 @@ if (isset($_GET['activate_user'])) {
|
||||
$row = userForRequest($_GET['activate_user']);
|
||||
$user_id = intval($row['user_id']);
|
||||
|
||||
// Only a user who isn't already using a seat can push the count over the limit
|
||||
if ((intval($row['user_status']) !== 1 || $row['user_archived_at']) && agentUserLimitReached()) {
|
||||
// Only a user who isn't already using a seat can push the count over the limit - and an API /
|
||||
// service account takes none (functions/service_account.php)
|
||||
if ((intval($row['user_status']) !== 1 || $row['user_archived_at']) && !serviceAccountIs($user_id) && agentUserLimitReached()) {
|
||||
flashAlert(agentUserLimitMessage(), 'error');
|
||||
redirect();
|
||||
}
|
||||
@@ -443,7 +451,8 @@ if (isset($_POST['restore_user'])) {
|
||||
$row = userForRequest($_POST['user_id'] ?? 0);
|
||||
$user_id = intval($row['user_id']);
|
||||
|
||||
if (agentUserLimitReached()) {
|
||||
// An API / service account takes no seat (functions/service_account.php)
|
||||
if (!serviceAccountIs($user_id) && agentUserLimitReached()) {
|
||||
flashAlert(agentUserLimitMessage(), 'error');
|
||||
redirect();
|
||||
}
|
||||
@@ -549,7 +558,7 @@ if (isset($_POST['bulk_disable_users']) || isset($_POST['bulk_activate_users']))
|
||||
if ($row['user_archived_at'] || intval($row['user_status']) === ($activate ? 1 : 0)) {
|
||||
continue;
|
||||
}
|
||||
if ($activate && agentUserLimitReached()) {
|
||||
if ($activate && !serviceAccountIs($user_id) && agentUserLimitReached()) {
|
||||
$kept[] = $row['user_name'];
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ if (serviceAccountsReady()) {
|
||||
$shows[$view_key]['where'] .= ' AND user_service_account = 0';
|
||||
}
|
||||
$shows = array_slice($shows, 0, array_search('archived', array_keys($shows), true), true)
|
||||
+ ['service' => ['label' => 'API accounts', 'icon' => 'fa-plug', 'where' => 'user_archived_at IS NULL AND user_service_account = 1', 'title' => 'Logins only for API keys to act as - left out of every agent list, and unable to sign in']]
|
||||
+ ['service' => ['label' => 'API accounts', 'icon' => 'fa-plug', 'where' => 'user_archived_at IS NULL AND user_service_account = 1', 'title' => 'Logins only for API keys to act as - left out of every agent list, unable to sign in, and taking no seat']]
|
||||
+ $shows;
|
||||
}
|
||||
$show = isset($shows[$_GET['show'] ?? '']) ? ($_GET['show'] ?? '') : '';
|
||||
@@ -201,7 +201,8 @@ if (isset($shows['invited'])) {
|
||||
// Those who can sign in to the portal
|
||||
$view_counts['portal'] = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM users $portal_joins WHERE $portal_filters AND " . PORTAL_USER_ON_SQL))[0]);
|
||||
|
||||
// Agent user limit (set in config.php, 0 / unset = unlimited) - an invite waiting holds a seat
|
||||
// Agent user limit (set in config.php, 0 / unset = unlimited) - an invite waiting holds a seat, an API /
|
||||
// service account doesn't (functions/service_account.php)
|
||||
$agent_user_limit = getAgentUserLimit();
|
||||
$agent_user_count = getActiveAgentUserCount();
|
||||
$agent_invites_holding = userInvitesHoldingSeats();
|
||||
@@ -231,14 +232,14 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<h3 class="card-title mt-2"><i class="fas fa-fw fa-users me-2"></i>Users
|
||||
<?php if ($agent_user_limit > 0) { ?>
|
||||
<span class="badge rounded-pill text-bg-<?= $agent_user_limit_reached ? 'danger' : 'secondary' ?> fw-normal ms-2"
|
||||
title="<?= $agent_user_count ?> active agent<?= $agent_user_count === 1 ? '' : 's' ?><?= $agent_invites_holding ? " and $agent_invites_holding invite" . ($agent_invites_holding === 1 ? '' : 's') . ' waiting' : '' ?>, of the agent user limit <?= $managed_limit_by !== '' ? 'set by ' . escapeHtml($managed_limit_by) : 'set for this installation' ?>">
|
||||
title="<?= $agent_user_count ?> active agent<?= $agent_user_count === 1 ? '' : 's' ?><?= $agent_invites_holding ? " and $agent_invites_holding invite" . ($agent_invites_holding === 1 ? '' : 's') . ' waiting' : '' ?>, of the agent user limit <?= $managed_limit_by !== '' ? 'set by ' . escapeHtml($managed_limit_by) : 'set for this installation' ?><?= serviceAccountsReady() ? ' - API / service accounts take none' : '' ?>">
|
||||
<?= $agent_user_count + $agent_invites_holding ?> of <?= $agent_user_limit ?> seats
|
||||
</span>
|
||||
<?php } ?>
|
||||
</h3>
|
||||
<div class="card-tools">
|
||||
<div class="btn-group">
|
||||
<?php if ($agent_user_limit_reached) { ?>
|
||||
<?php if ($agent_user_limit_reached && !serviceAccountsReady()) { ?>
|
||||
<button type="button" class="btn btn-primary" disabled title="Every seat is taken - disable or archive a user<?= $agent_invites_holding ? ', or cancel an invite,' : '' ?> first">
|
||||
<i class="fas fa-user-plus"></i><span class="d-none d-lg-inline ms-2">New User</span>
|
||||
</button>
|
||||
|
||||
@@ -1101,7 +1101,9 @@ function getProductsForAutocomplete($mysqli, $client_id = 0): string
|
||||
* An active agent is user_type 1, enabled and not archived. Disabled and archived
|
||||
* users do not use a seat. An invite waiting and in date does
|
||||
* (userInvitesHoldingSeats(), functions/user_invite.php) - it is a seat promised.
|
||||
* The manager's support user doesn't: it is the manager's, not one of theirs.
|
||||
* The manager's support user doesn't: it is the manager's, not one of theirs. Nor does an API /
|
||||
* service account (functions/service_account.php): it can't sign in, so nobody uses ITFlow as it -
|
||||
* it is an integration's login for its API keys.
|
||||
*/
|
||||
function getAgentUserLimit(): int
|
||||
{
|
||||
@@ -1122,7 +1124,7 @@ function getActiveAgentUserCount(): int
|
||||
$support_user_id = managedSupportUserId();
|
||||
|
||||
$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(user_id) FROM users WHERE user_type = 1 AND user_status = 1 AND user_archived_at IS NULL"
|
||||
. ($support_user_id ? " AND user_id <> $support_user_id" : '')));
|
||||
. serviceAccountsOutSql() . ($support_user_id ? " AND user_id <> $support_user_id" : '')));
|
||||
|
||||
return intval($row[0]);
|
||||
}
|
||||
|
||||
@@ -572,7 +572,8 @@ function managedReport(): array
|
||||
$clients = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(*) FROM clients WHERE client_archived_at IS NULL AND client_lead = 0"))[0] ?? 0);
|
||||
|
||||
// Who holds the seats - the active agents (not the support user, which takes none), then the
|
||||
// invites waiting in date - as getAgentSeatsTaken() counts them
|
||||
// invites waiting in date - as getAgentSeatsTaken() counts them. API / service accounts are
|
||||
// listed with 'service' set, and take none either (functions/service_account.php)
|
||||
$agent_list = [];
|
||||
$support_user_id = managedSupportUserId();
|
||||
$service = function_exists('serviceAccountsReady') && serviceAccountsReady();
|
||||
|
||||
@@ -13,6 +13,9 @@
|
||||
* - it can't sign in to ITFlow in a browser (login.php; includes/load_user_session.php ends a
|
||||
* session it already had)
|
||||
* - Admin > Users lists it in a section of its own; Roles and API Keys show it as before
|
||||
* - it takes no seat on the agent user limit (getActiveAgentUserCount(), functions/app.php), so
|
||||
* one can be added, enabled or restored when every seat is taken - but turning one back into
|
||||
* an agent who signs in takes a seat (serviceAccountLeavingNeedsSeat())
|
||||
*/
|
||||
|
||||
/** Whether the 3.8.1 update has run. */
|
||||
@@ -69,3 +72,19 @@ function serviceAccountSave($user_id, array $post) {
|
||||
mysqli_query($mysqli, "UPDATE users SET user_service_account = " . ($want ? 1 : 0) . " WHERE user_id = $user_id AND user_type = 1");
|
||||
return $want ? 'now an API / service account' : 'no longer an API / service account';
|
||||
}
|
||||
|
||||
/*
|
||||
* Would the Edit user window's $post turn $row - an active API / service account - into an agent who
|
||||
* signs in when every seat is taken? Then it waits for a free seat, or marking someone an API account
|
||||
* for a moment would be a way past the limit. A disabled or archived one takes no seat until it is
|
||||
* enabled or restored, and that checks then.
|
||||
*/
|
||||
function serviceAccountLeavingNeedsSeat(array $row, array $post) {
|
||||
if (!serviceAccountsReady() || !isset($post['service_account_present']) || !empty($post['service_account'])) {
|
||||
return false;
|
||||
}
|
||||
if (intval($row['user_status'] ?? 0) !== 1 || !empty($row['user_archived_at']) || !serviceAccountIs($row['user_id'] ?? 0)) {
|
||||
return false;
|
||||
}
|
||||
return agentUserLimitReached();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user