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

Add anonymous access support for private repositories (backend) #33257

Merged
merged 3 commits into from
Mar 28, 2025

Conversation

wxiaoguang
Copy link
Contributor

@wxiaoguang wxiaoguang commented Jan 14, 2025

Follow #33127

For #8649 and #639

This PR add backend logic and test for "anonymous access", it shares the same logic as "everyone access", so not too much change.

By the way, split SettingsPost into small functions to make it easier to make frontend-related changes in the future.

Next PR will add frontend support for "anonymous access"

https://github.com/go-gitea/gitea/pull/33257/files?diff=unified&w=1

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Jan 14, 2025
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jan 14, 2025
@wxiaoguang wxiaoguang changed the title Add anonymous access support WIP: Add anonymous access support Jan 14, 2025
@wxiaoguang wxiaoguang marked this pull request as draft January 14, 2025 05:21
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Jan 14, 2025
@wxiaoguang wxiaoguang added this to the 1.24.0 milestone Jan 14, 2025
@wxiaoguang wxiaoguang changed the title WIP: Add anonymous access support WIP: Add anonymous access support for private repositories Jan 21, 2025
@wxiaoguang wxiaoguang removed this from the 1.24.0 milestone Mar 3, 2025
@wxiaoguang
Copy link
Contributor Author

It seems there is no interest or strong requirement for this feature. Close, until there are enough interests and requirements.

@wxiaoguang wxiaoguang closed this Mar 21, 2025
@wxiaoguang wxiaoguang changed the title WIP: Add anonymous access support for private repositories WIP: Add anonymous access support for private repositories (need feedback) Mar 21, 2025
@moritz-h
Copy link

@wxiaoguang I have interest in this feature. I understood #639 with over 100 upvotes is exactly about this, so I think there is overall strong interest in this. #33127 is only half of what #639 was about.

@wxiaoguang wxiaoguang reopened this Mar 26, 2025
@wxiaoguang
Copy link
Contributor Author

Then let's try to bring it into Gitea 1.24

@wxiaoguang wxiaoguang force-pushed the support-anonymous-access branch 2 times, most recently from 2054b7f to de06c3c Compare March 28, 2025 04:44
@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 Mar 28, 2025
@wxiaoguang wxiaoguang force-pushed the support-anonymous-access branch from de06c3c to 095b61e Compare March 28, 2025 05:02
@pull-request-size pull-request-size bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 28, 2025
@wxiaoguang wxiaoguang changed the title WIP: Add anonymous access support for private repositories (need feedback) Add anonymous access support for private repositories (backend) Mar 28, 2025
@wxiaoguang wxiaoguang marked this pull request as ready for review March 28, 2025 05:04
@wxiaoguang wxiaoguang force-pushed the support-anonymous-access branch from 095b61e to 4ed6984 Compare March 28, 2025 05:09
@wxiaoguang wxiaoguang force-pushed the support-anonymous-access branch from 4ed6984 to ce57b0f Compare March 28, 2025 05:11
@wxiaoguang wxiaoguang added this to the 1.24.0 milestone Mar 28, 2025
@wxiaoguang wxiaoguang requested a review from lunny March 28, 2025 05:14
ctx.HTML(http.StatusOK, tplSettingsOptions)
return
}
handleSettingsPostUpdate(ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's better to move these changes to another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I have done it together, just don't want to waste time on another PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ps: this refactoring is related, to make it easier to make related frontend changes.

If we do not put it here, it will also be in "next PR", otherwise there will be one more PR, too many PRs.

@wxiaoguang wxiaoguang requested review from kerwin612 and hiifong March 28, 2025 07:13
@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 Mar 28, 2025
@@ -171,27 +179,38 @@ func (p *Permission) LogString() string {
format += "\n\tunitsMode[%-v]: %-v"
args = append(args, key.LogString(), value.LogString())
}
format += "\n\tanonymousAccessMode: %-v"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can use the string builder for better performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function won't be called in production. So it doesn't affect performance.

@@ -209,6 +228,11 @@ func finalProcessRepoUnitPermission(user *user_model.User, perm *Permission) {
break
}
}
for t := range perm.anonymousAccessMode {
if shouldKeep = shouldKeep || u.Type == t; shouldKeep {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's what I prefer to write: shouldKeep |= u.Type == t, But that's just my personal opinion, and there's nothing wrong with writing it that way

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then it needs 2 lines. Current code only uses one line .......

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right.

@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 Mar 28, 2025
@wxiaoguang wxiaoguang added the skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features. label Mar 28, 2025
@wxiaoguang wxiaoguang merged commit 0d2607a into go-gitea:main Mar 28, 2025
26 checks passed
@wxiaoguang wxiaoguang deleted the support-anonymous-access branch March 28, 2025 14:42
@wxiaoguang
Copy link
Contributor Author

Next: Add anonymous access support for private repositories #34051

zjjhot added a commit to zjjhot/gitea that referenced this pull request Mar 31, 2025
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  Add toggleClass function in dom.ts (go-gitea#34063)
  Add a config option to block "expensive" pages for anonymous users (go-gitea#34024)
  add additional ReplaceAll in pathsep to cater for different pathsep (go-gitea#34061)
  [skip ci] Updated translations via Crowdin
  enable staticcheck QFxxxx rules (go-gitea#34064)
  update to golangci-lint v2 (go-gitea#34054)
  Add descriptions for private repo public access settings and improve the UI (go-gitea#34057)
  Add anonymous access support for private/unlisted repositories (go-gitea#34051)
  Hide activity contributors, recent commits and code frequrency left tabs if there is no code permission (go-gitea#34053)
  Update action status badge layout (go-gitea#34018)
  Add anonymous access support for private repositories (backend) (go-gitea#33257)
  Simplify emoji rendering (go-gitea#34048)
  Adjust the layout of the toolbar on the Issues/Projects page (go-gitea#33667)
  Fix bug on downloading job logs (go-gitea#34041)
  Fix git client accessing renamed repo  (go-gitea#34034)
  Decouple Batch from git.Repository to simplify usage without requiring the creation of a Repository struct. (go-gitea#34001)
  fix org repo creation being limited by user limits (go-gitea#34030)
  Fix the issue with error message logging for the `check-attr` command on Windows OS. (go-gitea#34035)
  Try to fix check-attr bug (go-gitea#34029)
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. modifies/go Pull requests that update Go code modifies/migrations size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. skip-changelog This PR is irrelevant for the (next) changelog, for example bug fixes for unreleased features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants