feat: get options method

This commit is contained in:
Denis Gukov 2024-07-06 22:33:16 +05:00
parent 8ec19ab3b4
commit b0e766355a
6 changed files with 174 additions and 0 deletions

19
api/options.go Normal file
View File

@ -0,0 +1,19 @@
package api
import (
"github.com/ansible-semaphore/semaphore/api/helpers"
"github.com/ansible-semaphore/semaphore/db"
"github.com/gorilla/context"
"net/http"
)
func getOptions(w http.ResponseWriter, r *http.Request) {
currentUser := context.Get(r, "user").(*db.User)
if !currentUser.Admin {
helpers.WriteJSON(w, http.StatusForbidden, map[string]string{
"error": "User must be admin",
})
return
}
}

View File

@ -109,6 +109,7 @@ type Store interface {
// if a rollback exists
TryRollbackMigration(version Migration)
GetOptions() (map[string]string, error)
GetOption(key string) (string, error)
SetOption(key string, value string) error

View File

@ -5,6 +5,15 @@ import (
"github.com/ansible-semaphore/semaphore/db"
)
func (d *BoltDb) GetOptions() (res map[string]string, err error) {
var options []db.Option
err = d.getObjects(0, db.OptionProps, db.RetrieveQueryParams{}, nil, &options)
for _, opt := range options {
res[opt.Key] = opt.Value
}
return
}
func (d *BoltDb) SetOption(key string, value string) error {
opt := db.Option{

View File

@ -22,6 +22,15 @@ func (d *SqlDb) SetOption(key string, value string) error {
return err
}
func (d *SqlDb) GetOptions() (res map[string]string, err error) {
var options []db.Option
err = d.getObjects(0, db.OptionProps, db.RetrieveQueryParams{}, &options)
for _, opt := range options {
res[opt.Key] = opt.Value
}
return
}
func (d *SqlDb) getOption(key string) (value string, err error) {
q := squirrel.Select("*").
From("`"+db.OptionProps.TableName+"`").

136
web/src/views/Apps.vue Normal file
View File

@ -0,0 +1,136 @@
<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
<div v-if="items != null">
<EditDialog
v-model="editDialog"
save-button-text="Save"
:title="$t('editUser')"
@save="loadItems()"
>
<template v-slot:form="{ onSave, onError, needSave, needReset }">
<UserForm
:project-id="projectId"
:item-id="itemId"
@save="onSave"
@error="onError"
:need-save="needSave"
:need-reset="needReset"
:is-admin="true"
/>
</template>
</EditDialog>
<YesNoDialog
:title="$t('deleteUser')"
:text="$t('askDeleteUser')"
v-model="deleteItemDialog"
@yes="deleteItem(itemId)"
/>
<v-toolbar flat >
<v-btn
icon
class="mr-4"
@click="returnToProjects()"
>
<v-icon>mdi-arrow-left</v-icon>
</v-btn>
<v-toolbar-title>{{ $t('Applications') }}</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn
color="primary"
@click="editItem('new')"
>{{ $t('New App') }}</v-btn>
</v-toolbar>
<v-data-table
:headers="headers"
:items="items"
class="mt-4"
:footer-props="{ itemsPerPageOptions: [20] }"
>
<template v-slot:item.external="{ item }">
<v-icon v-if="item.external">mdi-checkbox-marked</v-icon>
<v-icon v-else>mdi-checkbox-blank-outline</v-icon>
</template>
<template v-slot:item.alert="{ item }">
<v-icon v-if="item.alert">mdi-checkbox-marked</v-icon>
<v-icon v-else>mdi-checkbox-blank-outline</v-icon>
</template>
<template v-slot:item.admin="{ item }">
<v-icon v-if="item.admin">mdi-checkbox-marked</v-icon>
<v-icon v-else>mdi-checkbox-blank-outline</v-icon>
</template>
<template v-slot:item.actions="{ item }">
<div style="white-space: nowrap">
<v-btn
icon
class="mr-1"
@click="askDeleteItem(item.id)"
:disabled="item.id === userId"
>
<v-icon>mdi-delete</v-icon>
</v-btn>
<v-btn
icon
class="mr-1"
@click="editItem(item.id)"
>
<v-icon>mdi-pencil</v-icon>
</v-btn>
</div>
</template>
</v-data-table>
</div>
</template>
<script>
import EventBus from '@/event-bus';
import YesNoDialog from '@/components/YesNoDialog.vue';
import ItemListPageBase from '@/components/ItemListPageBase';
import EditDialog from '@/components/EditDialog.vue';
export default {
mixins: [ItemListPageBase],
components: {
YesNoDialog,
EditDialog,
},
methods: {
getHeaders() {
return [{
text: '',
value: 'id',
}, {
text: this.$i18n.t('title'),
value: 'Title',
width: '100%',
}, {
text: this.$i18n.t('actions'),
value: 'actions',
sortable: false,
}];
},
async returnToProjects() {
EventBus.$emit('i-open-last-project');
},
getItemsUrl() {
return '/api/apps';
},
getSingleItemUrl() {
return `/api/apps/${this.itemId}`;
},
getEventName() {
return 'i-app';
},
},
};
</script>

View File