-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
251 additions
and
22 deletions.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2022 Woodpecker Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package migration | ||
|
||
import ( | ||
"fmt" | ||
|
||
"xorm.io/xorm" | ||
|
||
"github.com/woodpecker-ci/woodpecker/server/model" | ||
) | ||
|
||
var addOrgID = task{ | ||
name: "add-org-id", | ||
required: true, | ||
fn: func(sess *xorm.Session) error { | ||
if err := sess.Sync(new(model.User)); err != nil { | ||
return fmt.Errorf("sync new models failed: %w", err) | ||
} | ||
|
||
// get all users | ||
var users []*model.User | ||
if err := sess.Find(&users); err != nil { | ||
return fmt.Errorf("find all repos failed: %w", err) | ||
} | ||
|
||
for _, user := range users { | ||
org := &model.Org{} | ||
has, err := sess.Where("name = ?", user.Login).Get(org) | ||
if err != nil { | ||
return fmt.Errorf("getting org failed: %w", err) | ||
} else if !has { | ||
org = &model.Org{ | ||
Name: user.Login, | ||
IsUser: true, | ||
} | ||
if _, err := sess.Insert(org); err != nil { | ||
return fmt.Errorf("inserting org failed: %w", err) | ||
} | ||
} | ||
user.OrgID = org.ID | ||
if _, err := sess.Cols("user_org_id").Update(user); err != nil { | ||
return fmt.Errorf("updating user failed: %w", err) | ||
} | ||
} | ||
|
||
return dropTableColumns(sess, "secrets", "secret_owner") | ||
}, | ||
} |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<template> | ||
<Panel> | ||
<div class="flex flex-row border-b mb-4 pb-4 items-center dark:border-wp-background-100"> | ||
<div class="ml-2"> | ||
<h1 class="text-xl text-wp-text-100">{{ $t('user.settings.secrets.secrets') }}</h1> | ||
<p class="text-sm text-wp-text-alt-100"> | ||
{{ $t('user.settings.secrets.desc') }} | ||
<DocsLink :topic="$t('user.settings.secrets.secrets')" url="docs/usage/secrets" /> | ||
</p> | ||
</div> | ||
<Button | ||
v-if="selectedSecret" | ||
class="ml-auto" | ||
:text="$t('user.settings.secrets.show')" | ||
start-icon="back" | ||
@click="selectedSecret = undefined" | ||
/> | ||
<Button v-else class="ml-auto" :text="$t('user.settings.secrets.add')" start-icon="plus" @click="showAddSecret" /> | ||
</div> | ||
|
||
<SecretList | ||
v-if="!selectedSecret" | ||
v-model="secrets" | ||
i18n-prefix="user.settings.secrets." | ||
:is-deleting="isDeleting" | ||
@edit="editSecret" | ||
@delete="deleteSecret" | ||
/> | ||
|
||
<SecretEdit | ||
v-else | ||
v-model="selectedSecret" | ||
i18n-prefix="user.settings.secrets." | ||
:is-saving="isSaving" | ||
@save="createSecret" | ||
@cancel="selectedSecret = undefined" | ||
/> | ||
</Panel> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { cloneDeep } from 'lodash'; | ||
import { computed, ref } from 'vue'; | ||
import { useI18n } from 'vue-i18n'; | ||
import Button from '~/components/atomic/Button.vue'; | ||
import DocsLink from '~/components/atomic/DocsLink.vue'; | ||
import Panel from '~/components/layout/Panel.vue'; | ||
import SecretEdit from '~/components/secrets/SecretEdit.vue'; | ||
import SecretList from '~/components/secrets/SecretList.vue'; | ||
import useApiClient from '~/compositions/useApiClient'; | ||
import { useAsyncAction } from '~/compositions/useAsyncAction'; | ||
import useAuthentication from '~/compositions/useAuthentication'; | ||
import useNotifications from '~/compositions/useNotifications'; | ||
import { usePagination } from '~/compositions/usePaginate'; | ||
import { Secret, WebhookEvents } from '~/lib/api/types'; | ||
const emptySecret = { | ||
name: '', | ||
value: '', | ||
image: [], | ||
event: [WebhookEvents.Push], | ||
}; | ||
const apiClient = useApiClient(); | ||
const notifications = useNotifications(); | ||
const i18n = useI18n(); | ||
const { user } = useAuthentication(); | ||
if (!user) { | ||
throw new Error('Unexpected: Unauthenticated'); | ||
} | ||
const selectedSecret = ref<Partial<Secret>>(); | ||
const isEditingSecret = computed(() => !!selectedSecret.value?.id); | ||
async function loadSecrets(page: number): Promise<Secret[] | null> { | ||
if (!user) { | ||
throw new Error('Unexpected: Unauthenticated'); | ||
} | ||
return apiClient.getOrgSecretList(user.org_id, page); | ||
} | ||
const { resetPage, data: secrets } = usePagination(loadSecrets, () => !selectedSecret.value); | ||
const { doSubmit: createSecret, isLoading: isSaving } = useAsyncAction(async () => { | ||
if (!selectedSecret.value) { | ||
throw new Error("Unexpected: Can't get secret"); | ||
} | ||
if (isEditingSecret.value) { | ||
await apiClient.updateOrgSecret(user.org_id, selectedSecret.value); | ||
} else { | ||
await apiClient.createOrgSecret(user.org_id, selectedSecret.value); | ||
} | ||
notifications.notify({ | ||
title: i18n.t(isEditingSecret.value ? 'user.settings.secrets.saved' : 'user.settings.secrets.created'), | ||
type: 'success', | ||
}); | ||
selectedSecret.value = undefined; | ||
resetPage(); | ||
}); | ||
const { doSubmit: deleteSecret, isLoading: isDeleting } = useAsyncAction(async (_secret: Secret) => { | ||
await apiClient.deleteOrgSecret(user.org_id, _secret.name); | ||
notifications.notify({ title: i18n.t('user.settings.secrets.deleted'), type: 'success' }); | ||
resetPage(); | ||
}); | ||
function editSecret(secret: Secret) { | ||
selectedSecret.value = cloneDeep(secret); | ||
} | ||
function showAddSecret() { | ||
selectedSecret.value = cloneDeep(emptySecret); | ||
} | ||
</script> |
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
Oops, something went wrong.