Skip to content
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

chore(api): support ignore password if login source type is LDAP for creating user API #28491

Merged
merged 4 commits into from
Dec 19, 2023

Conversation

appleboy
Copy link
Member

  • Modify the Password field in CreateUserOption struct to remove the Required tag
  • Update the v1_json.tmpl template to include the email field and remove the password field

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 16, 2023
@pull-request-size pull-request-size bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Dec 16, 2023
@github-actions github-actions bot added the modifies/api This PR adds API routes or modifies them label Dec 16, 2023
@appleboy appleboy added this to the 1.21.3 milestone Dec 16, 2023
@lunny
Copy link
Member

lunny commented Dec 16, 2023

Maybe we need to check whether the user is a plain type or other type?

@lunny lunny modified the milestones: 1.21.3, 1.22.0 Dec 16, 2023
@appleboy
Copy link
Member Author

We only support login type as LDAP so we need to ignore the password field for checking the request body.

@appleboy
Copy link
Member Author

You can see the admin page for creating users in LDAP source type.

image

@appleboy appleboy changed the title chore(api): support ignore password if login source type is LDAP chore(api): support ignore password if login source type is LDAP for creating user API Dec 16, 2023
@pull-request-size pull-request-size bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 16, 2023
@appleboy
Copy link
Member Author

@lunny Add checking in Plain type.

routers/api/v1/admin/user.go Outdated Show resolved Hide resolved
- Modify the `Password` field in `CreateUserOption` struct to remove the `Required` tag
- Update the `v1_json.tmpl` template to include the `email` field and remove the `password` field

Signed-off-by: appleboy <appleboy.tw@gmail.com>
- Add validation for password requirement in CreateUser function

Signed-off-by: appleboy <appleboy.tw@gmail.com>
…r function

- Modify the condition for `u.LoginType` and `form.Password` in `CreateUser` function
- Add an empty line in `CreateUser` function

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@pull-request-size pull-request-size bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 18, 2023
@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 Dec 18, 2023
@appleboy
Copy link
Member Author

@lunny Can we backport the PR to the 1.21.3 version?

@lunny lunny added backport/v1.21 This PR should be backported to Gitea 1.21 type/bug labels Dec 18, 2023
@wxiaoguang
Copy link
Contributor

Could you elaborate the reason why it needs to "create a user without password"?

If you are using LDAP, I think you could just "sync" the LDAP users into Gitea, then no need to call the "create user API"?

@appleboy
Copy link
Member Author

appleboy commented Dec 19, 2023

@wxiaoguang

Our company is currently in the process of migrating from Bitbucket to Gitea service. Since Bitbucket is integrated with LDAP authentication, there are 20,000 users in LDAP. However, we only want to migrate the users who are currently using Bitbucket to Gitea, rather than transferring all users.

I have developed a migration tool that, during the project conversion, adds users based on project permissions. Therefore, it requires the use of the "add user" API. The login source will be filled with LDAP, and when using LDAP, there is no need to provide a password.

https://github.com/appleboy/BitbucketServer2Gitea

@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 Dec 19, 2023
@lunny lunny added the reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. label Dec 19, 2023
@lunny lunny enabled auto-merge (squash) December 19, 2023 01:58
@lunny
Copy link
Member

lunny commented Dec 19, 2023

@wxiaoguang

Our company is currently in the process of migrating from Bitbucket to Gitea service. Since Bitbucket is integrated with LDAP authentication, there are 20,000 users in LDAP. However, we only want to migrate the users who are currently using Bitbucket to Gitea, rather than transferring all users.

I have developed a migration tool that, during the project conversion, adds users based on project permissions. Therefore, it requires the use of the "add user" API. The login source will be filled with LDAP, and when using LDAP, there is no need to provide a password.

https://github.com/appleboy/BitbucketServer2Gitea

BTW: any chance to merge the logic into Gitea? So we can have a new migrate from bitbucket like others.

@lunny lunny merged commit 14ffdf6 into go-gitea:main Dec 19, 2023
25 checks passed
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Dec 19, 2023
…creating user API (go-gitea#28491)

- Modify the `Password` field in `CreateUserOption` struct to remove the
`Required` tag
- Update the `v1_json.tmpl` template to include the `email` field and
remove the `password` field

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@GiteaBot GiteaBot added backport/done All backports for this PR have been created and removed reviewed/wait-merge This pull request is part of the merge queue. It will be merged soon. labels Dec 19, 2023
@appleboy appleboy deleted the api branch December 19, 2023 02:54
lunny pushed a commit that referenced this pull request Dec 19, 2023
…creating user API (#28491) (#28525)

Backport #28491 by @appleboy

- Modify the `Password` field in `CreateUserOption` struct to remove the
`Required` tag
- Update the `v1_json.tmpl` template to include the `email` field and
remove the `password` field

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
Co-authored-by: Bo-Yi Wu <appleboy.tw@gmail.com>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Dec 19, 2023
* giteaofficial/main:
  Fix duplicate ID when deleting repo (go-gitea#28520)
  chore(api): support ignore password if login source type is LDAP for creating user API (go-gitea#28491)
  Update go dependencies (go-gitea#28518)
  Bump google/go-github to v57 (go-gitea#28514)
  Only check online runner when detecting matching runners in workflows (go-gitea#28286)
  Add orphaned topic consistency check (go-gitea#28507)
  Improve the prompt for "ssh-keygen sign" (go-gitea#28509)
fuxiaohei pushed a commit to fuxiaohei/gitea that referenced this pull request Jan 17, 2024
…creating user API (go-gitea#28491)

- Modify the `Password` field in `CreateUserOption` struct to remove the
`Required` tag
- Update the `v1_json.tmpl` template to include the `email` field and
remove the `password` field

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
silverwind pushed a commit to silverwind/gitea that referenced this pull request Feb 20, 2024
…creating user API (go-gitea#28491)

- Modify the `Password` field in `CreateUserOption` struct to remove the
`Required` tag
- Update the `v1_json.tmpl` template to include the `email` field and
remove the `password` field

---------

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport/done All backports for this PR have been created backport/v1.21 This PR should be backported to Gitea 1.21 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants