Skip to content

fix org repo creation being limited by user limits (#34030) #34044

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions templates/repo/create.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
<div class="ui attached segment">
{{template "base/alert" .}}
{{template "repo/create_helper" .}}

{{if not .CanCreateRepo}}
<div class="ui negative message">
<p>{{ctx.Locale.TrN .MaxCreationLimit "repo.form.reach_limit_of_creation_1" "repo.form.reach_limit_of_creation_n" .MaxCreationLimit}}</p>
</div>
{{end}}
<div id="create-repo-error-message" class="ui negative message tw-text-center tw-hidden"></div>
<div class="inline required field {{if .Err_Owner}}error{{end}}">
<label>{{ctx.Locale.Tr "repo.owner"}}</label>
<div class="ui selection owner dropdown">
Expand All @@ -26,7 +21,11 @@
</span>
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
<div class="menu">
<div class="item truncated-item-container" data-value="{{.SignedUser.ID}}" title="{{.SignedUser.Name}}">
<div class="item truncated-item-container" data-value="{{.SignedUser.ID}}" title="{{.SignedUser.Name}}"
{{if not .CanCreateRepo}}
data-create-repo-disallowed-prompt="{{ctx.Locale.TrN .MaxCreationLimit "repo.form.reach_limit_of_creation_1" "repo.form.reach_limit_of_creation_n" .MaxCreationLimit}}"
{{end}}
>
{{ctx.AvatarUtils.Avatar .SignedUser 28 "mini"}}
<span class="truncated-item-name">{{.SignedUser.ShortName 40}}</span>
</div>
Expand Down Expand Up @@ -209,7 +208,7 @@
<br>
<div class="inline field">
<label></label>
<button class="ui primary button{{if not .CanCreateRepo}} disabled{{end}}">
<button class="ui primary button">
{{ctx.Locale.Tr "repo.create_repo"}}
</button>
</div>
Expand Down
16 changes: 15 additions & 1 deletion web_src/js/features/repo-template.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import $ from 'jquery';
import {htmlEscape} from 'escape-goat';
import {hideElem, showElem} from '../utils/dom.ts';
import {hideElem, querySingleVisibleElem, showElem, toggleElem} from '../utils/dom.ts';

const {appSubUrl} = window.config;

Expand All @@ -21,6 +21,20 @@ export function initRepoTemplateSearch() {
checkTemplate();

const changeOwner = function () {
const elUid = document.querySelector<HTMLInputElement>('#uid');
const elForm = elUid.closest('form');
const elSubmitButton = querySingleVisibleElem<HTMLInputElement>(elForm, '.ui.primary.button');
const elCreateRepoErrorMessage = elForm.querySelector('#create-repo-error-message');
const elOwnerItem = document.querySelector(`.ui.selection.owner.dropdown .menu > .item[data-value="${CSS.escape(elUid.value)}"]`);
hideElem(elCreateRepoErrorMessage);
elSubmitButton.disabled = false;
if (elOwnerItem) {
elCreateRepoErrorMessage.textContent = elOwnerItem.getAttribute('data-create-repo-disallowed-prompt') ?? '';
const hasError = Boolean(elCreateRepoErrorMessage.textContent);
toggleElem(elCreateRepoErrorMessage, hasError);
elSubmitButton.disabled = hasError;
}

$('#repo_template_search')
.dropdown({
apiSettings: {
Expand Down