-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
feat(web): Add org removal functionality to admin user details page #38013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
karthikbhandary2
wants to merge
4
commits into
go-gitea:main
Choose a base branch
from
karthikbhandary2:org-remove
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <div class="flex-divided-list items-with-main"> | ||
| {{range .Users}} | ||
| <div class="item tw-items-center"> | ||
| <div class="item-leading"> | ||
| {{ctx.AvatarUtils.Avatar . 48}} | ||
| </div> | ||
| <div class="item-main"> | ||
| <div class="item-title"> | ||
| {{template "shared/user/name" .}} | ||
| {{if .Visibility.IsPrivate}} | ||
| <span class="ui basic tiny label">{{ctx.Locale.Tr "repo.desc.private"}}</span> | ||
| {{end}} | ||
| </div> | ||
| <div class="item-body"> | ||
| {{if .Location}} | ||
| <span class="flex-text-inline">{{svg "octicon-location"}}{{.Location}}</span> | ||
| {{end}} | ||
| <span class="flex-text-inline">{{svg "octicon-calendar"}}{{ctx.Locale.Tr "user.joined_on" (DateUtils.AbsoluteShort .CreatedUnix)}}</span> | ||
| </div> | ||
| </div> | ||
| <div class="item-trailing"> | ||
| <form method="post" action="{{$.Link}}/orgs/{{.ID}}/remove"> | ||
| {{$.CsrfTokenHtml}} | ||
| <button class="ui red tiny button" type="submit">{{ctx.Locale.Tr "remove"}}</button> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| {{else}} | ||
| <div class="item"> | ||
| {{ctx.Locale.Tr "search.no_results"}} | ||
| </div> | ||
| {{end}} | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Copyright 2026 The Gitea Authors. All rights reserved. | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| package integration | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "gitea.dev/models/organization" | ||
| "gitea.dev/models/unittest" | ||
| user_model "gitea.dev/models/user" | ||
| "gitea.dev/tests" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestAdminRemoveUserFromOrg(t *testing.T) { | ||
| defer tests.PrepareTestEnv(t)() | ||
|
|
||
| // Admin user | ||
| session := loginUser(t, "user1") | ||
|
|
||
| // User to remove from org | ||
| user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}) | ||
| org := unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}) | ||
|
|
||
| // Verify user is in org | ||
| isMember, err := organization.IsOrganizationMember(t.Context(), org.ID, user.ID) | ||
| assert.NoError(t, err) | ||
| assert.True(t, isMember) | ||
|
|
||
| // Remove user from org | ||
| req := NewRequest(t, "POST", "/-/admin/users/4/orgs/3/remove") | ||
| session.MakeRequest(t, req, http.StatusSeeOther) | ||
|
|
||
| // Verify user is no longer in org | ||
| isMember, err = organization.IsOrganizationMember(t.Context(), org.ID, user.ID) | ||
| assert.NoError(t, err) | ||
| assert.False(t, isMember) | ||
| } | ||
|
|
||
| func TestAdminRemoveUserFromAllOrgs(t *testing.T) { | ||
| defer tests.PrepareTestEnv(t)() | ||
|
|
||
| // Admin user | ||
| session := loginUser(t, "user1") | ||
|
|
||
| // User to remove from all orgs (user4 is not a last owner) | ||
| user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4}) | ||
|
|
||
| // Get count of orgs user is in before removal | ||
| orgCount, err := organization.GetOrganizationCount(t.Context(), user) | ||
| assert.NoError(t, err) | ||
| assert.Positive(t, orgCount, "User should be in at least one org") | ||
|
|
||
| // Remove user from all orgs | ||
| req := NewRequest(t, "POST", "/-/admin/users/4/orgs/remove-all") | ||
| session.MakeRequest(t, req, http.StatusSeeOther) | ||
|
|
||
| // Verify user is no longer in any orgs | ||
| orgCountAfter, err := organization.GetOrganizationCount(t.Context(), user) | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, int64(0), orgCountAfter, "User should not be in any orgs") | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this option should be given?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is given because we are going to remove the user from all the orgs (including limited and private). Since this is behind admin only route, it is restricted to only admins and regular users cant see this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this option mean it only includes private organizations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it means give everything (public, limited and private) and not to filter them out.