Provider ready
This commit is contained in:
parent
1d38f399fc
commit
eb2c8ca572
|
@ -157,7 +157,7 @@ func DomainHandler(c *gin.Context) {
|
||||||
type apiDomain struct {
|
type apiDomain struct {
|
||||||
Id int64 `json:"id"`
|
Id int64 `json:"id"`
|
||||||
IdUser int64 `json:"id_owner"`
|
IdUser int64 `json:"id_owner"`
|
||||||
IdSource int64 `json:"id_source"`
|
IdProvider int64 `json:"id_provider"`
|
||||||
DomainName string `json:"domain"`
|
DomainName string `json:"domain"`
|
||||||
ZoneHistory []happydns.ZoneMeta `json:"zone_history"`
|
ZoneHistory []happydns.ZoneMeta `json:"zone_history"`
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ func GetDomain(c *gin.Context) {
|
||||||
ret := &apiDomain{
|
ret := &apiDomain{
|
||||||
Id: domain.Id,
|
Id: domain.Id,
|
||||||
IdUser: domain.IdUser,
|
IdUser: domain.IdUser,
|
||||||
IdSource: domain.IdProvider,
|
IdProvider: domain.IdProvider,
|
||||||
DomainName: domain.DomainName,
|
DomainName: domain.DomainName,
|
||||||
ZoneHistory: []happydns.ZoneMeta{},
|
ZoneHistory: []happydns.ZoneMeta{},
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,12 +50,16 @@ func declareProvidersRoutes(cfg *config.Options, router *gin.RouterGroup) {
|
||||||
router.GET("/providers", getProviders)
|
router.GET("/providers", getProviders)
|
||||||
router.POST("/providers", addProvider)
|
router.POST("/providers", addProvider)
|
||||||
|
|
||||||
|
apiProvidersMetaRoutes := router.Group("/providers/:pid")
|
||||||
|
apiProvidersMetaRoutes.Use(ProviderMetaHandler)
|
||||||
|
|
||||||
|
apiProvidersMetaRoutes.DELETE("", deleteProvider)
|
||||||
|
|
||||||
apiProviderRoutes := router.Group("/providers/:pid")
|
apiProviderRoutes := router.Group("/providers/:pid")
|
||||||
apiProviderRoutes.Use(ProviderHandler)
|
apiProviderRoutes.Use(ProviderHandler)
|
||||||
|
|
||||||
apiProviderRoutes.GET("", getProvider)
|
apiProviderRoutes.GET("", getProvider)
|
||||||
//router.PUT("/api/providers/:sid", apiAuthHandler(providerHandler(updateProvider)))
|
apiProviderRoutes.PUT("", UpdateProvider)
|
||||||
//router.DELETE("/api/providers/:sid", apiAuthHandler(providerMetaHandler(deleteProvider)))
|
|
||||||
|
|
||||||
apiProviderRoutes.GET("/domains", getDomainsHostedByProvider)
|
apiProviderRoutes.GET("/domains", getDomainsHostedByProvider)
|
||||||
|
|
||||||
|
@ -109,6 +113,34 @@ func DecodeProvider(c *gin.Context) (*happydns.ProviderCombined, int, error) {
|
||||||
return src, http.StatusOK, nil
|
return src, http.StatusOK, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ProviderMetaHandler(c *gin.Context) {
|
||||||
|
// Extract provider ID
|
||||||
|
pid, err := strconv.ParseInt(string(c.Param("pid")), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": fmt.Sprintf("Invalid provider id: %s", err.Error())})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get a valid user
|
||||||
|
user := myUser(c)
|
||||||
|
if user == nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{"errmsg": "User not defined."})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve provider meta
|
||||||
|
providermeta, err := storage.MainStore.GetProviderMeta(user, pid)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Provider not found."})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Continue
|
||||||
|
c.Set("providermeta", providermeta)
|
||||||
|
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
|
||||||
func ProviderHandler(c *gin.Context) {
|
func ProviderHandler(c *gin.Context) {
|
||||||
// Extract provider ID
|
// Extract provider ID
|
||||||
pid, err := strconv.ParseInt(string(c.Param("pid")), 10, 64)
|
pid, err := strconv.ParseInt(string(c.Param("pid")), 10, 64)
|
||||||
|
@ -163,6 +195,55 @@ func addProvider(c *gin.Context) {
|
||||||
c.JSON(http.StatusOK, s)
|
c.JSON(http.StatusOK, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func UpdateProvider(c *gin.Context) {
|
||||||
|
provider := c.MustGet("provider").(*happydns.ProviderCombined)
|
||||||
|
|
||||||
|
src, statuscode, err := DecodeProvider(c)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithStatusJSON(statuscode, gin.H{"errmsg": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
src.Id = provider.Id
|
||||||
|
src.OwnerId = provider.OwnerId
|
||||||
|
|
||||||
|
if err := storage.MainStore.UpdateProvider(src); err != nil {
|
||||||
|
log.Println("%s unable to UpdateProvider: %w", c.ClientIP(), err)
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to update the provider. Please try again later."})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, src)
|
||||||
|
}
|
||||||
|
|
||||||
|
func deleteProvider(c *gin.Context) {
|
||||||
|
user := c.MustGet("LoggedUser").(*happydns.User)
|
||||||
|
providermeta := c.MustGet("providermeta").(*happydns.ProviderMeta)
|
||||||
|
|
||||||
|
// Check if the provider has no more domain associated
|
||||||
|
domains, err := storage.MainStore.GetDomains(user)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("%s unable to GetDomains for user id=%x email=%s: %w", c.ClientIP(), user.Id, user.Email, err)
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to perform this action. Please try again later."})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, domain := range domains {
|
||||||
|
if domain.IdProvider == providermeta.Id {
|
||||||
|
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "You cannot delete this provider because there is still some domains associated with it."})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := storage.MainStore.DeleteProvider(providermeta); err != nil {
|
||||||
|
log.Println("%s unable to DeleteProvider %x for user id=%x email=%s: %w", c.ClientIP(), providermeta.Id, user.Id, user.Email, err)
|
||||||
|
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "Sorry, we are currently unable to delete your provider. Please try again later."})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusNoContent, nil)
|
||||||
|
}
|
||||||
|
|
||||||
func getDomainsHostedByProvider(c *gin.Context) {
|
func getDomainsHostedByProvider(c *gin.Context) {
|
||||||
provider := c.MustGet("provider").(*happydns.ProviderCombined)
|
provider := c.MustGet("provider").(*happydns.ProviderCombined)
|
||||||
|
|
||||||
|
|
|
@ -120,7 +120,7 @@ export default {
|
||||||
|
|
||||||
if (!this.showAlreadyImported) {
|
if (!this.showAlreadyImported) {
|
||||||
ret = ret.filter(
|
ret = ret.filter(
|
||||||
d => !this.domains_getAll.find(i => i.domain === d)
|
d => !this.domains_getAll.find(i => i.domain === d + '.')
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,6 +230,8 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
|
this.$emit('no-domains-list-change', true)
|
||||||
|
this.importableDomains = false
|
||||||
this.$root.$bvToast.toast(
|
this.$root.$bvToast.toast(
|
||||||
error.response.data.errmsg, {
|
error.response.data.errmsg, {
|
||||||
title: this.$t('errors.domain-access'),
|
title: this.$t('errors.domain-access'),
|
||||||
|
@ -238,7 +240,6 @@ export default {
|
||||||
toaster: 'b-toaster-content-right'
|
toaster: 'b-toaster-content-right'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
this.$router.replace('/providers/' + encodeURIComponent(this.myProvider._id))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!this.showDomainsWithActions || this.providerSpecs_getAll[this.provider._srctype].capabilities.indexOf('ListDomainsWithActions') === -1) {
|
if (!this.showDomainsWithActions || this.providerSpecs_getAll[this.provider._srctype].capabilities.indexOf('ListDomainsWithActions') === -1) {
|
||||||
|
|
|
@ -96,14 +96,14 @@
|
||||||
<b-icon icon="trash-fill" /> {{ $t('domains.stop') }}
|
<b-icon icon="trash-fill" /> {{ $t('domains.stop') }}
|
||||||
</b-button>
|
</b-button>
|
||||||
|
|
||||||
<b-form v-if="sources_getAll && sources_getAll[domain.id_source]" class="mt-5">
|
<b-form v-if="providers_getAll && providers_getAll[domain.id_provider]" class="mt-5">
|
||||||
<label class="font-weight-bolder">{{ $t('domains.view.source') }}:</label>
|
<label class="font-weight-bolder">{{ $t('domains.view.provider') }}:</label>
|
||||||
<div class="pr-2 pl-2">
|
<div class="pr-2 pl-2">
|
||||||
<b-button class="p-3 w-100 text-left" type="button" variant="outline-info" @click="goToSource()">
|
<b-button class="p-3 w-100 text-left" type="button" variant="outline-info" @click="goToProvider()">
|
||||||
<div class="d-inline-block text-center" style="width: 50px;">
|
<div class="d-inline-block text-center" style="width: 50px;">
|
||||||
<img :src="'/api/providers/_specs/' + providers_getAll[domain.id_provider]._srctype + '/icon.png'" :alt="providers_getAll[domain.id_provider]._srctype" :title="providers_getAll[domain.id_provider]._srctype" style="max-width: 100%; max-height: 2.5em; margin: -.6em .4em -.6em -.6em">
|
<img :src="'/api/providers/_specs/' + providers_getAll[domain.id_provider]._srctype + '/icon.png'" :alt="providers_getAll[domain.id_provider]._srctype" :title="providers_getAll[domain.id_provider]._srctype" style="max-width: 100%; max-height: 2.5em; margin: -.6em .4em -.6em -.6em">
|
||||||
</div>
|
</div>
|
||||||
{{ sources_getAll[domain.id_source]._comment }}
|
{{ providers_getAll[domain.id_provider]._comment }}
|
||||||
</b-button>
|
</b-button>
|
||||||
</div>
|
</div>
|
||||||
</b-form>
|
</b-form>
|
||||||
|
@ -192,7 +192,7 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
...mapGetters('domains', ['domains_getDetailed', 'sortedDomains']),
|
...mapGetters('domains', ['domains_getDetailed', 'sortedDomains']),
|
||||||
...mapGetters('sources', ['sources_getAll'])
|
...mapGetters('providers', ['providers_getAll'])
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
|
@ -209,7 +209,7 @@ export default {
|
||||||
this.displayFormat = localStorage.getItem('displayFormat')
|
this.displayFormat = localStorage.getItem('displayFormat')
|
||||||
}
|
}
|
||||||
this.$store.dispatch('domains/getAllMyDomains')
|
this.$store.dispatch('domains/getAllMyDomains')
|
||||||
this.$store.dispatch('sources/getAllMySources')
|
this.$store.dispatch('providers/getAllMyProviders')
|
||||||
this.updateDomainInfo()
|
this.updateDomainInfo()
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -251,8 +251,8 @@ export default {
|
||||||
this.updateDomainInfo()
|
this.updateDomainInfo()
|
||||||
},
|
},
|
||||||
|
|
||||||
goToSource () {
|
goToProvider () {
|
||||||
this.$router.push('/sources/' + encodeURIComponent(this.domain.id_source))
|
this.$router.push('/providers/' + encodeURIComponent(this.domain.id_provider))
|
||||||
},
|
},
|
||||||
|
|
||||||
detachDomain () {
|
detachDomain () {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user