-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
change update visiblity ux #25856
Closed
Closed
change update visiblity ux #25856
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
157a25e
change update visiblity ux
mohammad258852 47e7ec7
Merge branch 'main' into visiblity
mohammad258852 e4e9bd4
Merge branch 'main' into visiblity
mohammad258852 3d01c46
move change visibility to danger zone
mohammad258852 2757fa3
fix a bug
mohammad258852 0df63a8
try not to combine label
mohammad258852 1801af3
remove safe function
mohammad258852 58064bb
Merge branch 'main' into visiblity
mohammad258852 c069a83
Merge branch 'main' into visiblity
mohammad258852 5b23f3a
fix style
mohammad258852 a4c5209
Merge branch 'main' into visiblity
mohammad258852 a11b4ae
Merge branch 'main' into visiblity
GiteaBot 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
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -168,15 +168,7 @@ func SettingsPost(ctx *context.Context) { | |
form.Private = repo.BaseRepo.IsPrivate || repo.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate | ||
} | ||
|
||
visibilityChanged := repo.IsPrivate != form.Private | ||
// when ForcePrivate enabled, you could change public repo to private, but only admin users can change private to public | ||
if visibilityChanged && setting.Repository.ForcePrivate && !form.Private && !ctx.Doer.IsAdmin { | ||
ctx.RenderWithErr(ctx.Tr("form.repository_force_private"), tplSettingsOptions, form) | ||
return | ||
} | ||
|
||
repo.IsPrivate = form.Private | ||
if err := repo_service.UpdateRepository(ctx, repo, visibilityChanged); err != nil { | ||
if err := repo_service.UpdateRepository(ctx, repo, false); err != nil { | ||
ctx.ServerError("UpdateRepository", err) | ||
return | ||
} | ||
|
@@ -815,6 +807,43 @@ func SettingsPost(ctx *context.Context) { | |
ctx.Flash.Success(ctx.Tr("repo.settings.wiki_deletion_success")) | ||
ctx.Redirect(ctx.Repo.RepoLink + "/settings") | ||
|
||
case "change-visiblity": | ||
if ctx.HasError() { | ||
ctx.HTML(http.StatusOK, tplSettingsOptions) | ||
return | ||
} | ||
if !ctx.Repo.IsOwner() { | ||
ctx.Error(http.StatusNotFound) | ||
return | ||
} | ||
if repo.Name != form.RepoName { | ||
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_repo_name"), tplSettingsOptions, nil) | ||
return | ||
} | ||
|
||
private := form.Private | ||
|
||
if repo.IsFork { | ||
private = repo.BaseRepo.IsPrivate || repo.BaseRepo.Owner.Visibility == structs.VisibleTypePrivate | ||
} | ||
|
||
visibilityChanged := repo.IsPrivate != private | ||
if visibilityChanged && setting.Repository.ForcePrivate && !private && !ctx.Doer.IsAdmin { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A useful comment is lost
|
||
ctx.RenderWithErr(ctx.Tr("form.repository_force_private"), tplSettingsOptions, form) | ||
return | ||
} | ||
|
||
repo.IsPrivate = private | ||
if err := repo_service.UpdateRepository(ctx, repo, visibilityChanged); err != nil { | ||
ctx.ServerError("UpdateRepository", err) | ||
return | ||
} | ||
|
||
log.Trace("Repository visibility settings updated: %s/%s", ctx.Repo.Owner.Name, repo.Name) | ||
|
||
ctx.Flash.Success(ctx.Tr("repo.settings.update_settings_success")) | ||
ctx.Redirect(ctx.Repo.RepoLink + "/settings") | ||
|
||
case "archive": | ||
if !ctx.Repo.IsOwner() { | ||
ctx.Error(http.StatusForbidden) | ||
|
This file contains 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 |
---|---|---|
|
@@ -26,14 +26,7 @@ | |
{{if not .Repository.IsFork}} | ||
<div class="inline field"> | ||
<label>{{.locale.Tr "repo.visibility"}}</label> | ||
<div class="ui checkbox" {{if and (not .Repository.IsPrivate) (gt .Repository.NumStars 0)}}data-tooltip-content="{{.locale.Tr "repo.stars_remove_warning"}}"{{end}}> | ||
{{if .IsAdmin}} | ||
<input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}> | ||
{{else}} | ||
<input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}{{if and $.ForcePrivate .Repository.IsPrivate}} readonly{{end}}> | ||
{{end}} | ||
<label>{{.locale.Tr "repo.visibility_helper" | Safe}} {{if .Repository.NumForks}}<span class="text red">{{.locale.Tr "repo.visibility_fork_helper"}}</span>{{end}}</label> | ||
</div> | ||
<span>{{if .Repository.IsPrivate}}{{.locale.Tr "settings.visibility.private"}}{{else}}{{.locale.Tr "settings.visibility.public"}}{{end}}</span> | ||
</div> | ||
{{end}} | ||
<div class="field {{if .Err_Description}}error{{end}}"> | ||
|
@@ -753,6 +746,40 @@ | |
</div> | ||
{{end}} | ||
|
||
{{if not .Repository.IsFork}} | ||
<div class="divider"></div> | ||
|
||
<div class="item"> | ||
<div class="ui right"> | ||
<button class="ui basic red show-modal button" data-modal="#repo-visibility-modal"> | ||
{{if not .Repository.IsPrivate}} | ||
{{.locale.Tr "repo.visibility_helper_private" | Safe}} | ||
lafriks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{{else}} | ||
{{.locale.Tr "repo.visibility_helper_public" | Safe}} | ||
{{end}} | ||
</button> | ||
</div> | ||
<div> | ||
<h5> | ||
{{if not .Repository.IsPrivate}} | ||
{{.locale.Tr "repo.visibility_helper_private" | Safe}} | ||
{{else}} | ||
{{.locale.Tr "repo.visibility_helper_public" | Safe}} | ||
{{end}} | ||
</h5> | ||
{{if and (not .Repository.IsPrivate) (gt .Repository.NumStars 0)}} | ||
<p>{{.locale.Tr "repo.stars_remove_warning"}}</p> | ||
{{end}} | ||
{{if and (not .Repository.IsPrivate) (.Repository.NumForks)}} | ||
<p class="text red">{{.locale.Tr "repo.visibility_fork_helper"}}</p> | ||
{{end}} | ||
{{if .Repository.IsPrivate}} | ||
<p class="text red">{{.locale.Tr "repo.visibility_credential"}}</p> | ||
{{end}} | ||
</div> | ||
</div> | ||
{{end}} | ||
|
||
<div class="divider"></div> | ||
|
||
<div class="item"> | ||
|
@@ -960,6 +987,50 @@ | |
</div> | ||
{{end}} | ||
|
||
{{if not .Repository.IsFork}} | ||
<div class="ui small modal" id="repo-visibility-modal"> | ||
<div class="header"> | ||
{{.locale.Tr "repo.visibility"}} | ||
</div> | ||
<div class="content"> | ||
<div class="ui warning message"> | ||
{{if not .Repository.IsPrivate}} | ||
{{.locale.Tr "repo.stars_remove_warning"}}<br> | ||
{{.locale.Tr "repo.visibility_fork_helper"}} | ||
{{else}} | ||
{{.locale.Tr "repo.visibility_credential"}} | ||
{{end}} | ||
</div> | ||
<form class="ui form" action="{{.Link}}" method="post"> | ||
{{.CsrfTokenHtml}} | ||
<input type="hidden" name="action" value="change-visiblity"> | ||
<input type="hidden" name="private" value={{if .Repository.IsPrivate}}"false"{{else}}"true"{{end}}> | ||
<div class="field"> | ||
<label> | ||
{{.locale.Tr "repo.settings.transfer_form_title"}} | ||
<span class="text red">{{.Repository.Name}}</span> | ||
</label> | ||
</div> | ||
<div class="required field"> | ||
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label> | ||
<input id="repo_name" name="repo_name" required> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are many |
||
</div> | ||
|
||
<div class="text right actions"> | ||
<button class="ui cancel button">{{.locale.Tr "settings.cancel"}}</button> | ||
<button class="ui red button"> | ||
{{if not .Repository.IsPrivate}} | ||
{{.locale.Tr "repo.visibility_helper_private"}} | ||
{{else}} | ||
{{.locale.Tr "repo.visibility_helper_public"}} | ||
{{end}} | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
{{end}} | ||
|
||
{{if not .Repository.IsMirror}} | ||
<div class="ui g-modal-confirm modal" id="archive-repo-modal"> | ||
<div class="header"> | ||
|
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.
The old code doesn't have such check.
IIRC the
IsOwner
should have been correctly checked by a middleware for this handler.