Skip to content

feat(web): Add org removal functionality to admin user details page - #38013

Merged
bircni merged 25 commits into
go-gitea:mainfrom
karthikbhandary2:org-remove
Aug 29, 2026
Merged

feat(web): Add org removal functionality to admin user details page#38013
bircni merged 25 commits into
go-gitea:mainfrom
karthikbhandary2:org-remove

Conversation

@karthikbhandary2

Copy link
Copy Markdown
Contributor

Related Issues

Closes #37071

Summary

Adds the ability for administrators to remove users from organizations directly from the admin user details page (/-/admin/users/{userid}). This feature provides both individual organization removal and bulk removal from all organizations.

Motivation

Currently, administrators need to navigate to each organization separately to remove a user from multiple organizations. This enhancement streamlines user management by allowing admins to perform these actions directly from the user details page.

Implementation

Backend (Go)

routers/web/admin/users.go (Modified)
  • Added RemoveUserFromOrg() - Removes a user from a single organization
  • Added RemoveUserFromAllOrgs() - Removes a user from all organizations
  • Both functions reuse the existing org_service.RemoveOrgUser() service
  • Handles edge cases:
    • Last owner protection (cannot remove if user is the only owner)
    • Partial removal tracking (shows count of successful removals)
    • Empty organization list
  • Added org_service import
routers/web/web.go (Modified)
  • Registered POST route: /{userid}/orgs/{orgid}/remove
  • Registered POST route: /{userid}/orgs/remove-all

Frontend (Templates)

templates/admin/user/view.tmpl (Modified)
  • Added "Remove All" button in the Organizations section header
  • Added confirmation modal for "Remove All" action with:
    • Descriptive warning message
    • User name and organization count
    • Cancel and confirm buttons
templates/admin/user/view_orgs.tmpl (New)
  • Custom organization list template with individual "Remove" buttons
  • Based on explore/user_list.tmpl but with admin-specific actions
  • Shows organization details:
    • Name
    • Visibility
    • Join date
  • Individual "Remove" button for each organization

Localization

options/locale/locale_en-US.json (Modified)

Added:

  • admin.users.org_removed - Success message for single removal
  • admin.users.all_orgs_removed - Success message for bulk removal
  • admin.users.no_orgs_to_remove - Info message when user has no organizations
  • admin.users.no_orgs_removed - Error message when no removals succeeded
  • admin.users.some_orgs_removed - Partial success message with count
  • admin.users.remove_all_orgs_title - Modal title
  • admin.users.remove_all_orgs_desc - Modal confirmation message

Tests

tests/integration/admin_user_org_test.go (New)
  • TestAdminRemoveUserFromOrg - Tests single organization removal
  • TestAdminRemoveUserFromAllOrgs - Tests bulk removal from all organizations
  • Verifies database state changes
  • Tests with non-owner users to avoid last-owner constraint

Features

  • ✅ Remove user from a single organization
  • ✅ Remove user from all organizations with confirmation
  • ✅ Last owner protection (prevents removing if user is the sole owner)
  • ✅ Graceful error handling with informative messages
  • ✅ Partial removal tracking (shows how many removals succeeded)
  • ✅ Integration tests

UI Changes

Before

No option to remove users from organizations on the admin user page.

After

  1. "Remove All" button at the top-right of the Organizations section
  2. Individual "Remove" button next to each organization
  3. Confirmation modal for bulk removal

Screenshots

image image

Security Considerations

  • Reuses existing org_service.RemoveOrgUser() which includes proper permission checks
  • CSRF protection on all POST requests
  • Only accessible to administrators
  • Cannot remove the last owner of an organization

Testing

Run integration tests:

go test -v ./tests/integration -run TestAdminRemoveUserFrom

Development Note

This PR was developed with assistance from Amazon Q Developer and Gemini.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jun 6, 2026
@karthikbhandary2
karthikbhandary2 marked this pull request as ready for review June 7, 2026 07:50
@github-actions github-actions Bot added the type/feature Completely new functionality. Can only be merged if feature freeze is not active. label Jun 7, 2026
Comment thread options/locale/locale_en-US.json
Comment thread routers/web/admin/users.go Outdated
Comment thread routers/web/admin/users.go Outdated
techknowlogick and others added 4 commits June 9, 2026 11:28
Signed-off-by: techknowlogick <techknowlogick@gitea.com>
Signed-off-by: Karthik Bhandary <34509856+karthikbhandary2@users.noreply.github.com>
@karthikbhandary2

Copy link
Copy Markdown
Contributor Author

Anything else?

@karthikbhandary2

Copy link
Copy Markdown
Contributor Author

@lunny please check and let me know when you can

@lunny lunny added this to the 28.0.0 milestone Jul 15, 2026
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Aug 23, 2026
@karthikbhandary2

Copy link
Copy Markdown
Contributor Author

@bircni one question. What is considered worthy of release/highlight?

@wxiaoguang

Copy link
Copy Markdown
Contributor

I believe it needs to be carefully reviewed and have some clean-ups.

For example: we have removed CsrfTokenHtml since Dec 25, 2025 (Replace CSRF cookie with CrossOriginProtection - #36183), but there are a lot in this PR.

Also suggest to follow: https://github.com/go-gitea/gitea/blob/main/docs/guidelines-backend.md#golang-html-template (especially for the {{range .Users}} loop)

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Aug 29, 2026
@bircni bircni added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Aug 29, 2026
@bircni
bircni enabled auto-merge (squash) August 29, 2026 07:41
@bircni
bircni merged commit 88974d2 into go-gitea:main Aug 29, 2026
24 checks passed
@GiteaBot GiteaBot removed the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/feature Completely new functionality. Can only be merged if feature freeze is not active.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Add Admin "Exit" Functionality for Organizations in User Details

6 participants