theonedev/onedev · error · BadRequestException

Should only enable normal users

Error message

Should only enable normal users

What it means

OneDev's REST endpoint POST /users/{userId}/enable refuses to enable (un-disable) any account whose id is not a normal user id. User.ROOT_ID and other reserved/system accounts (ids <= ROOT_ID, e.g. root) cannot be enabled via this API. The guard exists because system accounts must not be lifecycle-managed through the REST API.

Source

Thrown at server-core/src/main/java/io/onedev/server/rest/resource/UserResource.java:456

			throw new BadRequestException("Should only disable normal users");
		var user = userService.load(userId);
		userService.disable(user);

		auditService.audit(null, "disabled account \"" + user.getName() + "\" via RESTful API", null, null);

		return Response.ok().build();
    }

	@Api(order=1970, description="Enable user")
	@Path("/{userId}/enable")
    @POST
    public Response enableUser(@PathParam("userId") Long userId) {
		if (!subscriptionService.isSubscriptionActive())
			throw new NotAcceptableException("This operation requires active subscription");
		if (!SecurityUtils.isAdministrator()) 
			throw new UnauthorizedException();
		if (userId <= User.ROOT_ID)		
			throw new BadRequestException("Should only enable normal users");
		var user = userService.load(userId);
		userService.enable(user);

		auditService.audit(null, "enabled account \"" + user.getName() + "\" via RESTful API", null, null);

		return Response.ok().build();
    }

	@Api(order=1980, description="Convert to service account")
	@Path("/{userId}/convert-to-service-account")
    @POST
    public Response convertToServiceAccount(@PathParam("userId") Long userId) {
		if (!subscriptionService.isSubscriptionActive())
			throw new NotAcceptableException("This operation requires active subscription");
		if (!SecurityUtils.isAdministrator()) 
			throw new UnauthorizedException();
		if (userId <= User.ROOT_ID)		
			throw new BadRequestException("Should only convert normal users to service accounts");

View on GitHub (pinned to d44925c47c)

Solutions

  1. Verify the target user id is a normal (ordinary) user with id > User.ROOT_ID before calling the enable endpoint
  2. Look up the intended user via GET /users and use its actual id, excluding the root/system accounts
  3. Enable system/root-level accounts through the server UI or database administration instead of the REST API

Example fix

// before
curl -X POST .../users/1/enable   // id <= ROOT_ID -> 400
// after
const users = await rest.get('/users');
const target = users.find(u => u.id > 1 && u.name === 'alice');
await rest.post(`/users/${target.id}/enable`);
Defensive patterns

Strategy: validation

Validate before calling

if (typeof userId !== 'number' || userId <= 1) throw new Error('Only normal users (id > User.ROOT_ID) can be enabled');

Type guard

function isNormalUserId(id) { return typeof id === 'number' && Number.isInteger(id) && id > 1; }

Try / catch

try { await rest.post(`/users/${id}/enable`); } catch (e) { if (e.status === 400 && /normal users/.test(e.message)) { /* skip system account */ } else throw e; }

Prevention

When it happens

Trigger: Calling POST /rest/v1/users/{userId}/enable as an active-subscription administrator where userId <= User.ROOT_ID (e.g. the root account id or an id of 0/null resolved to a reserved account).

Common situations: Scripting bulk user management and iterating over a user list that includes the built-in root account; hardcoding id 1 or 0 assuming user ids start there; calling the endpoint on the wrong resource id.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of theonedev/onedev@d44925c47c (2026-09-06). Data as JSON: /api/errors/8518ee96ea6d07cf. Report an issue: GitHub.