Skip to content
Snippets Groups Projects
Unverified Commit 797e7654 authored by Martin Weise's avatar Martin Weise
Browse files

WIP

parent e830459f
No related branches found
No related tags found
2 merge requests!163Relase 1.3.0,!156Added readme to authentication service and added eureka service
...@@ -51,6 +51,19 @@ class DatabaseService { ...@@ -51,6 +51,19 @@ class DatabaseService {
}) })
} }
delete (id, databaseId) {
return new Promise((resolve, reject) => {
api.delete(`/api/container/${id}/database/${databaseId}`, { headers: { Accept: 'application/json' } })
.then(() => resolve())
.catch((error) => {
const { code, message } = error
console.error('Failed to delete database', error)
Vue.$toast.error(`[${code}] Failed to delete database: ${message}`)
reject(error)
})
})
}
modifyVisibility (id, databaseId, isPublic) { modifyVisibility (id, databaseId, isPublic) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
api.put(`/api/container/${id}/database/${databaseId}/visibility`, { is_public: isPublic }, { headers: { Accept: 'application/json' } }) api.put(`/api/container/${id}/database/${databaseId}/visibility`, { is_public: isPublic }, { headers: { Accept: 'application/json' } })
......
...@@ -73,6 +73,8 @@ ...@@ -73,6 +73,8 @@
</template> </template>
<script> <script>
import DatabaseService from '@/api/database.service'
import UserService from '@/api/user.service'
export default { export default {
props: { props: {
username: { username: {
...@@ -195,69 +197,49 @@ export default { ...@@ -195,69 +197,49 @@ export default {
await this.giveAccess() await this.giveAccess()
} }
}, },
async revokeAccess () { revokeAccess () {
this.loading = true this.loading = true
try { DatabaseService.revokeAccess(this.$route.params.container_id, this.$route.params.database_id, this.username)
const res = await this.$axios.delete(`/api/container/${this.$route.params.container_id}/database/${this.$route.params.database_id}/access/${this.username}`, this.config) .then(() => {
console.debug('revoke access', res.data)
this.$toast.success(`Successfully revoked access of ${this.username}`) this.$toast.success(`Successfully revoked access of ${this.username}`)
this.$emit('close-dialog', { success: true }) this.$emit('close-dialog', { success: true })
} catch (err) { })
console.log('revoke access', err) .finally(() => {
this.$toast.error('Could not revoke access to database')
}
this.loading = false this.loading = false
})
}, },
async modifyAccess () { modifyAccess () {
this.loading = true this.loading = true
try { DatabaseService.modifyAccess(this.$route.params.container_id, this.$route.params.database_id, this.username, this.modify.type)
const res = await this.$axios.put(`/api/container/${this.$route.params.container_id}/database/${this.$route.params.database_id}/access/${this.username}`, { .then(() => {
type: this.modify.type
}, this.config)
console.debug('give access', res.data)
this.$toast.success('Successfully modified access') this.$toast.success('Successfully modified access')
this.$emit('close-dialog', { success: true }) this.$emit('close-dialog', { success: true })
} catch (err) { })
console.log('modify access', err) .finally(() => {
this.$toast.error('Could not modify access to database')
}
this.loading = false this.loading = false
})
}, },
async giveAccess () { giveAccess () {
const username = this.modify.username const username = this.modify.username
this.loading = true this.loading = true
try { DatabaseService.giveAccess(this.$route.params.container_id, this.$route.params.database_id, this.username, this.modify.type)
const res = await this.$axios.post(`/api/container/${this.$route.params.container_id}/database/${this.$route.params.database_id}/access`, this.modify, this.config) .then(() => {
console.debug('give access', res.data)
this.$toast.success(`Successfully gave ${username} access`) this.$toast.success(`Successfully gave ${username} access`)
this.$emit('close-dialog', { success: true }) this.$emit('close-dialog', { success: true })
} catch (err) { })
if (err.response.status === 405) { .finally(() => {
this.$toast.error(`User ${username} already has access`)
this.loading = false
return
} else if (err.response.status === 404) {
this.$toast.error(`User ${username} does not exist`)
this.loading = false
return
}
console.log('give access', err)
this.$toast.error('Could not give access to database')
}
this.loading = false this.loading = false
})
}, },
async loadUsers () { loadUsers () {
this.loadingUsers = true this.loadingUsers = true
try { UserService.findAll()
const res = await this.$axios.get('/api/user', this.config) .then((users) => {
this.users = res.data.filter(u => u.username !== this.database.creator.username) this.users = users.filter(u => u.username !== this.database.creator.username)
console.debug('users', this.users) })
} catch (error) { .finally(() => {
console.error('Failed to load users', error) this.loading = false
const { message } = error.response.data })
this.$toast.error(`Failed to load users: ${message}`)
}
this.loadingUsers = false
}, },
init () { init () {
if (!this.username) { if (!this.username) {
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
</template> </template>
<script> <script>
import IdentifierService from '@/api/identifier.service'
export default { export default {
props: { props: {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
</template> </template>
<script> <script>
import IdentifierService from '@/api/identifier.service'
export default { export default {
props: { props: {
...@@ -35,41 +36,21 @@ export default { ...@@ -35,41 +36,21 @@ export default {
loading: false loading: false
} }
}, },
computed: {
token () {
return this.$store.state.token
},
config () {
if (this.token === null) {
return {
headers: { Accept: 'application/json' }
}
}
return {
headers: { Authorization: `Bearer ${this.token}`, Accept: 'application/json' }
}
}
},
methods: { methods: {
async download () { download () {
this.loading = true this.loading = true
try { IdentifierService.export(this.pid)
const config = this.config .then((data) => {
config.headers.Accept = this.contentType const url = window.URL.createObjectURL(new Blob([data]))
const res = await this.$axios.get(`/api/pid/${this.pid}`, config)
console.debug('export identifier', res)
const url = window.URL.createObjectURL(new Blob([res.data]))
const link = document.createElement('a') const link = document.createElement('a')
link.href = url link.href = url
link.setAttribute('download', this.filename) link.setAttribute('download', this.filename)
document.body.appendChild(link) document.body.appendChild(link)
link.click() link.click()
} catch (err) { })
console.error('Could not export identifier', err) .finally(() => {
this.$toast.error('Could not export identifier')
this.error = true
}
this.loading = false this.loading = false
})
} }
} }
} }
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
<script> <script>
import DBToolbar from '@/components/DBToolbar' import DBToolbar from '@/components/DBToolbar'
import DatabaseService from '@/api/database.service'
export default { export default {
components: { components: {
...@@ -71,34 +72,14 @@ export default { ...@@ -71,34 +72,14 @@ export default {
return this.confirm !== this.db.internalName return this.confirm !== this.db.internalName
} }
}, },
mounted () {
this.init()
},
methods: { methods: {
async deleteDatabase () { deleteDatabase () {
try { DatabaseService.delete(this.$route.params.container_id, this.$route.params.database_id)
await this.$axios.delete(`/api/database/${this.$route.params.database_id}`) .then(async () => {
this.$router.push({ path: '/databases' })
this.$toast.success(`Database "${this.db.name}" deleted.`) this.$toast.success(`Database "${this.db.name}" deleted.`)
} catch (err) { await this.$router.push({ path: '/databases' })
this.$toast.error('Could not delete database')
}
this.dialogDelete = false this.dialogDelete = false
}, })
async init () {
if (this.db != null) {
return
}
try {
this.loading = true
const res = await this.$axios.get(`/api/database/${this.$route.params.database_id}`)
console.debug('database', res.data)
this.$store.commit('SET_DATABASE', res.data)
this.loading = false
} catch (err) {
this.$toast.error('Could not load database')
this.loading = false
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment