Skip to content

feat: convert regular accounts to guests#1619

Open
ernolf wants to merge 2 commits into
mainfrom
ernolf/feat/convert-to-guest
Open

feat: convert regular accounts to guests#1619
ernolf wants to merge 2 commits into
mainfrom
ernolf/feat/convert-to-guest

Conversation

@ernolf

@ernolf ernolf commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an admin action to convert a regular account into a guest account, and lets guests have a free-form login name instead of one derived from their email.

Closes #1153
Closes #333
Related #1479

Convert accounts to guests

Create a user (just for testing):

$ NC_PASS=karltest occ user:add --password-from-env --display-name="Karl Test" -- karltest
The account "karltest" was created successfully
Display name set to "Karl Test"
$ occ user:info karltest
  - user_id: karltest
  - display_name: Karl Test
  - email:
  - cloud_id: karltest@global-social.net
  - enabled: true
  - groups:
  - quota: none
  - storage:
    - free: 1184627609600
    - used: 0
    - total: 1184627609600
    - relative: 0
    - quota: -3
  - first_seen: never
  - last_seen: never
  - user_directory: /nc/dat/data/karltest
  - backend: Database

In Administration settings → Users, the account's menu gains Convert to guest account.

image

A confirmation dialog explains the effect: the account keeps its login name and password but becomes a limited guest, restricted to the apps allowed for guests, and receives the default guest quota. The conversion cannot be undone automatically.

image

It is only possible for accounts that use the database backend, are not already a guest, and have never logged in (enforced in the UI and in the OCS endpoint).

After conversion the account's backend is Guests:

image

and it logs in with the same password:

image

It then appears in the guests list:

image

Use case: self-registration

A typical use case is self-registration through the registration app with "Require administrator approval" enabled: those accounts are created disabled and never logged in, so an administrator can downgrade them to guests instead of enabling them. Once such an account has logged in, conversion is no longer possible.

If you would rather registered users keep their email address as login name, enable "Force email as login name" in the registration app settings.

Custom guest login names

occ guests:add gains --uid to set a free-form login name, instead of always deriving the user ID from the email address (or its hash):

$ occ guests:add --help
Description:
  Add a new guest account

Usage:
  guests:add [options] [--] <created-by> <email>

Arguments:
  created-by                         User ID who is set as creator
  email                              Email address

Options:
      --uid=UID                      Login name (user ID) for the guest. If omitted, the email address is used (hashed when the privacy setting is enabled).
      --generate-password            Do not set an initial password
      --password-from-env            Read password from environment variable OC_PASS
      --display-name[=DISPLAY-NAME]  User name used in the web UI (can contain any characters) [default: ""]
      --language[=LANGUAGE]          Language [default: ""]
  -h, --help                         Display help for the given command. When no command is given display help for the list command
  -q, --quiet                        Do not output any message
  -V, --version                      Display this application version
      --ansi|--no-ansi               Force (or disable --no-ansi) ANSI output
  -n, --no-interaction               Do not ask any interactive question
      --no-warnings                  Skip global warnings, show command output only
  -v|vv|vvv, --verbose               Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Example — create a guest with a chosen login name and verify the user ID:

$ occ guests:add admin guest@example.com --uid=freddy
$ occ user:info freddy

The guests backend user-id guard is loosened accordingly to accept any non-empty id.

Implementation

  • ConversionService performs the transactional usersguests_users move (uid, display name, password hash and email preserved).
  • UsersController::convert() OCS endpoint (admin-only) with the eligibility checks above; route POST /api/v1/convert.
  • GuestManager::setGuestQuota() extracted so both newly created and converted guests get the configured default quota.
  • occ guests:add --uid for a free-form login name.
  • Unit tests for the backend guard, the --uid option, the controller endpoint and the conversion service.

Testing

Verified on a live instance (screenshots above): created a never-logged-in database account, converted it via the UI, confirmed the backend switched to Guests, the account logs in with the same password, and it appears in the guests list. The action is hidden for accounts that have logged in and for existing guests.

🤖 AI (if applicable)

  • The content of this PR was partly generated using AI
    Assisted-by: ClaudeCode:claude-opus-4-8

ernolf added 2 commits July 3, 2026 21:08
- add "Convert to guest account" for regular, never-logged-in database accounts (admin … menu action + OCS endpoint), keeping the login name and password
- add ConversionService for the transactional users -> guests_users move; extract GuestManager::setGuestQuota so converted accounts get the default guest quota
- allow a free-form guest login name via `occ guests:add --uid` instead of deriving the user ID from the email address
- loosen the guests backend user-id guard to accept any non-empty id

Closes #1153

Assisted-by: ClaudeCode:claude-opus-4-8
Signed-off-by: ernolf <raphael.gradenwitz@googlemail.com>
Signed-off-by: ernolf <raphael.gradenwitz@googlemail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Convert existing users to guest users Assign a specific username at guest creation

1 participant