mirror of
https://github.com/go-gitea/gitea.git
synced 2026-06-21 12:37:05 +02:00
easy copy
This commit is contained in:
parent
eb87aa3ab8
commit
b92117785a
@ -1126,6 +1126,7 @@
|
||||
"repo.migrate.ssh_key_owner_label": "Authenticate with",
|
||||
"repo.migrate.ssh_key_owner_org_default": "This organization's managed SSH key (default)",
|
||||
"repo.migrate.ssh_key_owner_personal": "Your personal managed SSH key (%s)",
|
||||
"repo.migrate.ssh_key_manage_link": "View and copy your public key",
|
||||
"repo.migrate.permission_denied": "You are not allowed to import local repositories.",
|
||||
"repo.migrate.permission_denied_blocked": "You cannot import from disallowed hosts. Please ask the admin to check ALLOWED_DOMAINS/ALLOW_LOCALNETWORKS/BLOCKED_DOMAINS settings.",
|
||||
"repo.migrate.invalid_local_path": "The local path is invalid. It doesn't exist or is not a directory.",
|
||||
|
||||
@ -89,10 +89,14 @@ func setManagedSSHKeyFingerprints(ctx *context.Context, ctxUser *user_model.User
|
||||
}
|
||||
|
||||
fingerprints := map[int64]string{}
|
||||
// keysURLs maps an org owner id to its managed SSH keys settings page, so the
|
||||
// form links to the right page to copy the key when authenticating as that org.
|
||||
keysURLs := map[int64]string{}
|
||||
if orgs, ok := ctx.Data["Orgs"].([]*organization.Organization); ok {
|
||||
for _, org := range orgs {
|
||||
if kp, err := ssh_module.GetOrCreateSSHKeypair(ctx, org.ID); err == nil {
|
||||
fingerprints[org.ID] = kp.Fingerprint
|
||||
keysURLs[org.ID] = org.OrganisationLink() + "/settings/ssh_keys"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -100,12 +104,18 @@ func setManagedSSHKeyFingerprints(ctx *context.Context, ctxUser *user_model.User
|
||||
if _, seen := fingerprints[ctxUser.ID]; !seen {
|
||||
if kp, err := ssh_module.GetOrCreateSSHKeypair(ctx, ctxUser.ID); err == nil {
|
||||
fingerprints[ctxUser.ID] = kp.Fingerprint
|
||||
if ctxUser.IsOrganization() {
|
||||
keysURLs[ctxUser.ID] = ctxUser.OrganisationLink() + "/settings/ssh_keys"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if data, err := json.Marshal(fingerprints); err == nil {
|
||||
ctx.Data["OwnerSSHFingerprintsJSON"] = string(data)
|
||||
}
|
||||
if data, err := json.Marshal(keysURLs); err == nil {
|
||||
ctx.Data["OwnerSSHKeysURLsJSON"] = string(data)
|
||||
}
|
||||
}
|
||||
|
||||
func handleMigrateError(ctx *context.Context, owner *user_model.User, err error, name string, tpl templates.TplName, form *forms.MigrateRepoForm) {
|
||||
|
||||
@ -10,12 +10,15 @@
|
||||
<div class="inline-right">
|
||||
<span class="ssh-key-label">{{ctx.Locale.Tr "repo.migrate.ssh_key_owner_personal" .SignedUser.Name}}</span>
|
||||
<code class="ssh-key-fingerprint">{{.SignedUserSSHFingerprint}}</code>
|
||||
<a href="{{AppSubUrl}}/user/settings/keys" target="_blank">{{ctx.Locale.Tr "repo.migrate.ssh_key_manage_link"}}</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="inline field ssh-key-owner-selector tw-hidden"
|
||||
data-signed-user-id="{{.SignedUser.ID}}"
|
||||
data-signed-user-fingerprint="{{.SignedUserSSHFingerprint}}"
|
||||
data-owner-fingerprints="{{.OwnerSSHFingerprintsJSON}}">
|
||||
data-owner-fingerprints="{{.OwnerSSHFingerprintsJSON}}"
|
||||
data-owner-keys-links="{{.OwnerSSHKeysURLsJSON}}"
|
||||
data-personal-keys-link="{{AppSubUrl}}/user/settings/keys">
|
||||
<label>{{ctx.Locale.Tr "repo.migrate.ssh_key_owner_label"}}</label>
|
||||
<div class="ui selection dropdown">
|
||||
<input id="ssh_key_owner_id" name="ssh_key_owner_id" type="hidden" value="0">
|
||||
@ -32,4 +35,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<span class="help">
|
||||
<a class="js-ssh-keys-link" href="{{AppSubUrl}}/user/settings/keys" target="_blank">{{ctx.Locale.Tr "repo.migrate.ssh_key_manage_link"}}</a>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@ -113,7 +113,10 @@ function initSSHKeyOwnerSelector(cloneAddrInput: HTMLInputElement) {
|
||||
|
||||
const signedUserID = selector.getAttribute('data-signed-user-id') ?? '';
|
||||
const ownerFingerprints: Record<string, string> = JSON.parse(selector.getAttribute('data-owner-fingerprints') || '{}');
|
||||
const ownerKeysURLs: Record<string, string> = JSON.parse(selector.getAttribute('data-owner-keys-links') || '{}');
|
||||
const personalKeysURL = selector.getAttribute('data-personal-keys-link') ?? '';
|
||||
const orgDefaultFingerprintEl = selector.querySelector<HTMLElement>('.menu .item[data-value="0"] .item-fingerprint');
|
||||
const keysLink = selector.querySelector<HTMLAnchorElement>('.js-ssh-keys-link');
|
||||
|
||||
function update() {
|
||||
const isSSH = isSSHURL(cloneAddrInput.value.trim());
|
||||
@ -137,10 +140,15 @@ function initSSHKeyOwnerSelector(cloneAddrInput: HTMLInputElement) {
|
||||
// Org target — show dropdown; populate the org-default item's fingerprint.
|
||||
if (fingerprintOnly) hideElem(fingerprintOnly);
|
||||
if (orgDefaultFingerprintEl) orgDefaultFingerprintEl.textContent = ownerFingerprints[targetUid] ?? '';
|
||||
// Point the link at the page holding the key that will actually be used:
|
||||
// the org's keys page for the org default, or the personal keys page.
|
||||
if (keysLink) {
|
||||
keysLink.href = hiddenId!.value === signedUserID ? personalKeysURL : (ownerKeysURLs[targetUid] ?? personalKeysURL);
|
||||
}
|
||||
showElem(selector!);
|
||||
}
|
||||
|
||||
for (const item of document.querySelectorAll<HTMLElement>('.owner.dropdown .menu .item')) {
|
||||
for (const item of document.querySelectorAll<HTMLElement>('.owner.dropdown .menu .item, .ssh-key-owner-selector .menu .item')) {
|
||||
item.addEventListener('click', () => setTimeout(update, 0));
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user