[host] make domain and database admin accessable
This commit is contained in:
parent
25a1f4f85b
commit
fd6fb63371
|
@ -8,9 +8,11 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
libapi "dev.sum7.eu/sum7/warehost/lib/api"
|
libapi "dev.sum7.eu/sum7/warehost/lib/api"
|
||||||
|
system "dev.sum7.eu/sum7/warehost/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getDatabase(ctx context.Context, w http.ResponseWriter) (database Database, returnerr *libapi.ErrorResult) {
|
func getDatabase(ctx context.Context, w http.ResponseWriter) (database Database, returnerr *libapi.ErrorResult) {
|
||||||
|
login := ctx.Value("login").(*system.Login)
|
||||||
profil := ctx.Value("profil").(*Profil)
|
profil := ctx.Value("profil").(*Profil)
|
||||||
id, err := strconv.ParseInt(pat.Param(ctx, "databaseid"), 10, 64)
|
id, err := strconv.ParseInt(pat.Param(ctx, "databaseid"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -20,7 +22,13 @@ func getDatabase(ctx context.Context, w http.ResponseWriter) (database Database,
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if login.Superadmin {
|
||||||
|
dbconnection.Where("id = ?", id).Find(&database)
|
||||||
|
} else {
|
||||||
dbconnection.Where(map[string]int64{"id": id, "profil": profil.ID}).Find(&database)
|
dbconnection.Where(map[string]int64{"id": id, "profil": profil.ID}).Find(&database)
|
||||||
|
}
|
||||||
|
|
||||||
if database.ID <= 0 {
|
if database.ID <= 0 {
|
||||||
returnerr = &libapi.ErrorResult{Fields: []string{"database"}, Message: "not found"}
|
returnerr = &libapi.ErrorResult{Fields: []string{"database"}, Message: "not found"}
|
||||||
}
|
}
|
||||||
|
@ -28,11 +36,16 @@ func getDatabase(ctx context.Context, w http.ResponseWriter) (database Database,
|
||||||
}
|
}
|
||||||
|
|
||||||
func databaseList(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
func databaseList(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
||||||
|
login := ctx.Value("login").(*system.Login)
|
||||||
profil := ctx.Value("profil").(*Profil)
|
profil := ctx.Value("profil").(*Profil)
|
||||||
returndata = false
|
returndata = false
|
||||||
logger := log.GetLog(r, "databaselist")
|
logger := log.GetLog(r, "databaselist")
|
||||||
var database []*Database
|
var database []*Database
|
||||||
|
if login.Superadmin && r.URL.Query().Get("filter") == "all" {
|
||||||
|
dbconnection.Find(&database)
|
||||||
|
} else {
|
||||||
dbconnection.Where("profil = ?", profil.ID).Find(&database)
|
dbconnection.Where("profil = ?", profil.ID).Find(&database)
|
||||||
|
}
|
||||||
logger.Info("done")
|
logger.Info("done")
|
||||||
returndata = database
|
returndata = database
|
||||||
return
|
return
|
||||||
|
|
|
@ -48,6 +48,10 @@ func TestAPIDatabase(t *testing.T) {
|
||||||
assertion.Equal(w.StatusCode, http.StatusOK)
|
assertion.Equal(w.StatusCode, http.StatusOK)
|
||||||
assertion.NotEqual(result.Data, false)
|
assertion.NotEqual(result.Data, false)
|
||||||
|
|
||||||
|
result, w = session.JSONRequest("GET", "/host/database?filter=all", nil)
|
||||||
|
assertion.Equal(w.StatusCode, http.StatusOK)
|
||||||
|
assertion.NotEqual(result.Data, false)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TEST databaseAdd
|
* TEST databaseAdd
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -9,9 +9,11 @@ import (
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
libapi "dev.sum7.eu/sum7/warehost/lib/api"
|
libapi "dev.sum7.eu/sum7/warehost/lib/api"
|
||||||
|
system "dev.sum7.eu/sum7/warehost/system"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getDomain(ctx context.Context, w http.ResponseWriter) (domain Domain, returnerr *libapi.ErrorResult) {
|
func getDomain(ctx context.Context, w http.ResponseWriter) (domain Domain, returnerr *libapi.ErrorResult) {
|
||||||
|
login := ctx.Value("login").(*system.Login)
|
||||||
profil := ctx.Value("profil").(*Profil)
|
profil := ctx.Value("profil").(*Profil)
|
||||||
id, err := strconv.ParseInt(pat.Param(ctx, "domainid"), 10, 64)
|
id, err := strconv.ParseInt(pat.Param(ctx, "domainid"), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -21,7 +23,12 @@ func getDomain(ctx context.Context, w http.ResponseWriter) (domain Domain, retur
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if login.Superadmin {
|
||||||
|
dbconnection.Where("id = ?", id).Find(&domain)
|
||||||
|
} else {
|
||||||
dbconnection.Where(map[string]int64{"id": id, "profil": profil.ID}).Find(&domain)
|
dbconnection.Where(map[string]int64{"id": id, "profil": profil.ID}).Find(&domain)
|
||||||
|
}
|
||||||
|
|
||||||
if domain.ID <= 0 {
|
if domain.ID <= 0 {
|
||||||
returnerr = &libapi.ErrorResult{Fields: []string{"domain"}, Message: "not found"}
|
returnerr = &libapi.ErrorResult{Fields: []string{"domain"}, Message: "not found"}
|
||||||
}
|
}
|
||||||
|
@ -29,11 +36,16 @@ func getDomain(ctx context.Context, w http.ResponseWriter) (domain Domain, retur
|
||||||
}
|
}
|
||||||
|
|
||||||
func domainList(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
func domainList(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
||||||
|
login := ctx.Value("login").(*system.Login)
|
||||||
profil := ctx.Value("profil").(*Profil)
|
profil := ctx.Value("profil").(*Profil)
|
||||||
returndata = false
|
returndata = false
|
||||||
logger := log.GetLog(r, "domainlist")
|
logger := log.GetLog(r, "domainlist")
|
||||||
var domain []*Domain
|
var domain []*Domain
|
||||||
|
if login.Superadmin && r.URL.Query().Get("filter") == "all" {
|
||||||
|
dbconnection.Find(&domain)
|
||||||
|
} else {
|
||||||
dbconnection.Where("profil = ?", profil.ID).Find(&domain)
|
dbconnection.Where("profil = ?", profil.ID).Find(&domain)
|
||||||
|
}
|
||||||
logger.Info("done")
|
logger.Info("done")
|
||||||
returndata = domain
|
returndata = domain
|
||||||
return
|
return
|
||||||
|
@ -73,6 +85,7 @@ func domainAdd(ctx context.Context, w http.ResponseWriter, r *http.Request) (ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func domainEdit(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
func domainEdit(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
||||||
|
login := ctx.Value("login").(*system.Login)
|
||||||
returndata = false
|
returndata = false
|
||||||
logger := log.GetLog(r, "domainedit")
|
logger := log.GetLog(r, "domainedit")
|
||||||
|
|
||||||
|
@ -92,6 +105,10 @@ func domainEdit(ctx context.Context, w http.ResponseWriter, r *http.Request) (re
|
||||||
domain.Mail = domainRequest.Mail
|
domain.Mail = domainRequest.Mail
|
||||||
domain.Web = domainRequest.Web
|
domain.Web = domainRequest.Web
|
||||||
|
|
||||||
|
if login.Superadmin {
|
||||||
|
domain.Active = domainRequest.Active
|
||||||
|
}
|
||||||
|
|
||||||
if err := dbconnection.Save(domain).Error; err != nil {
|
if err := dbconnection.Save(domain).Error; err != nil {
|
||||||
logger.Error("database: during modify host domain: ", err)
|
logger.Error("database: during modify host domain: ", err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
|
|
@ -48,6 +48,10 @@ func TestAPIDomain(t *testing.T) {
|
||||||
assertion.Equal(w.StatusCode, http.StatusOK)
|
assertion.Equal(w.StatusCode, http.StatusOK)
|
||||||
assertion.NotEqual(result.Data, false)
|
assertion.NotEqual(result.Data, false)
|
||||||
|
|
||||||
|
result, w = session.JSONRequest("GET", "/host/domain?filter=all", nil)
|
||||||
|
assertion.Equal(w.StatusCode, http.StatusOK)
|
||||||
|
assertion.NotEqual(result.Data, false)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TEST domainAdd
|
* TEST domainAdd
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -50,7 +50,7 @@ type Mail struct {
|
||||||
ID int64
|
ID int64
|
||||||
DomainID int64 `sql:"type:bigint NOT NULL REFERENCES host_domain(id) ON UPDATE CASCADE ON DELETE CASCADE;column:domain" json:"domain"`
|
DomainID int64 `sql:"type:bigint NOT NULL REFERENCES host_domain(id) ON UPDATE CASCADE ON DELETE CASCADE;column:domain" json:"domain"`
|
||||||
Name string `sql:"type:varchar(255);column:name" json:"name"`
|
Name string `sql:"type:varchar(255);column:name" json:"name"`
|
||||||
Forward string `sql:"type:varchar(255)[];column:forward" json:"forward"`
|
Forward []string `sql:"type:varchar(255)[];column:forward" json:"forward"`
|
||||||
LoginID int64 `sql:"type:bigint NOT NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"login"`
|
LoginID int64 `sql:"type:bigint NOT NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"login"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
//InvolveWebsiteHandler for api function to Verifie User ist loggedin
|
//InvolveWebsiteHandler for api function to Verifie User ist loggedin
|
||||||
func InvolveWebsiteHandler(h libapi.Handle) libapi.Handle {
|
func InvolveWebsiteHandler(h libapi.Handle) libapi.Handle {
|
||||||
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
return func(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
||||||
login := ctx.Value("login").(libsystem.Login)
|
login := ctx.Value("login").(*libsystem.Login)
|
||||||
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not logged in"}
|
returnerr = &libapi.ErrorResult{Fields: []string{"session"}, Message: "Not logged in"}
|
||||||
returndata = false
|
returndata = false
|
||||||
|
|
||||||
|
|
Reference in New Issue