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

change update visiblity ux #25856

Closed
wants to merge 12 commits into from
5 changes: 4 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,12 @@ template_helper = Make repository a template
template_description = Template repositories let users generate new repositories with the same directory structure, files, and optional settings.
visibility = Visibility
visibility_description = Only the owner or the organization members if they have rights, will be able to see it.
visibility_helper = Make Repository Private
visibility_helper_private = Make Repository Private
visibility_helper_public = Make Repository Public
visibility_helper_forced = Your site administrator forces new repositories to be private.
visibility_fork_helper = (Changing this will affect all forks.)
visibility_credential = With making repository public every one can see your code including imporant data in it
visibility.update_error = For making repository private go to danger zone
clone_helper = Need help cloning? Visit <a target="_blank" rel="noopener noreferrer" href="%s">Help</a>.
fork_repo = Fork Repository
fork_from = Fork From
Expand Down
47 changes: 38 additions & 9 deletions routers/web/repo/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Comment on lines +865 to +868
Copy link
Contributor

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.

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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

A useful comment is lost

// when ForcePrivate enabled, you could change public repo to private, but only admin users can change private to public

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)
Expand Down
87 changes: 79 additions & 8 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}">
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Copy link
Contributor

Choose a reason for hiding this comment

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

There are many id="repo_name" elements in this page. The "id" should be unique.

</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">
Expand Down