Remember Company At Sign In PR Review - edmozley/freeitsm GitHub Wiki
Start each sign-in in the company you last used - review
#409 by @cloudcogsio ยท Verdict: merge, with fixes ยท 5.8.0 (#3030)
Until now the company switcher's choice lived only in the session, so every sign-in started in the Default company and someone who works in another company - or in All companies - switched again every morning. A new personal preference, Preferences โ Company at sign-in โ Start in the company I last used, puts them back where they were. User page: Staff cross-company access. Internals: Preferences - Developer Guide.
It is off by default and shown only to someone who can reach more than one company. Opt-in on purpose: the company also decides where a new ticket is filed, so starting in yesterday's client company should be a choice, not a surprise.
What was checked
| Question | Result |
|---|---|
| Can the remembered row grant access? | No. The pick is stored in user_preferences (active_company), which the analyst can write themselves through set_user_preference.php. So tenancyRestoreRememberedCompany() treats it as a wish: the company must still exist, be active, and pass analystCanAccessTenant(); otherwise nothing of it is restored and the usual fallback applies |
| Does restoring "All companies" widen anything? | No. The switcher's own endpoint gives All companies no permission of its own - it is "every company this analyst may already see" - so restoring it grants nothing a click would not |
| Does it fight a pick made in this session? | No. It only fills a session with no company set, once per session and analyst; an explicit pick (setActiveTenantId() / setActiveTenantAll()) marks the session so it is never overwritten |
| Single-company installs | Untouched: both entry points return before the restore when there is one company |
| Cost on a page load | One indexed lookup until the session is filled; a read-only session cannot keep the "done" flag, so such a request may look again - still one lookup |
The branch's own test, tests/remember-company.php, covers the preference off, a company and All companies restored, a session pick winning, and a deactivated or no-longer-accessible company not restored - 16/16 on a test install.
What was fixed
- The Preferences switch test counted wrong. The branch raised
tests/preferences-switch-hit-area.phpfrom seven switch templates to eight but left the number of rendered switches at 8. But the notification-type template is drawn twice (once for tickets, once for tasks), so eight templates render nine switches, and the test failed with "Not all switch fixtures rendered." It now expects nine, with a comment saying why; 184 checks pass. The count was right before only because seven templates happened to render eight. - The help named a menu item that does not exist. The Tickets help said to turn the setting on "under My preferences"; the account menu says Preferences. It now says "under Preferences (your account menu)".
- Translations. The four new strings, in the eight languages kept at 100%, using each language's own words for the switcher, All companies and Preferences.
๐ Files
| File | Change |
|---|---|
๐ฃ includes/tenancy.php |
tenancyRememberCompany(), tenancyRestoreRememberedCompany(); called from getActiveTenantId() and isActiveTenantAll(); explicit picks mark the session |
๐ฃ api/system/set_active_tenant.php |
Saves each pick, whether or not the preference is on |
๐ฃ system/preferences/index.php, includes/preference_templates.php |
The switch, and its template section |
๐งช tests/remember-company.php |
New; tests/preferences-switch-hit-area.php count fixed |
๐ lang/*/system.php, lang/*/tickets.php |
remember_company_*, switcher_remember |