add webaccess and mailforward
This commit is contained in:
parent
1c07e35024
commit
3d88bbfacd
13
README.md
13
README.md
|
@ -4,4 +4,17 @@
|
|||
```
|
||||
ALTER TABLE login ALTER createat TYPE timestamptz;
|
||||
ALTER TABLE login ALTER lastloginat TYPE timestamptz;
|
||||
|
||||
|
||||
BEGIN;
|
||||
insert into host_web_webaccess (web,login) (select id,unnest(httpaccess) from host_web);
|
||||
ALTER TABLE host_web DROP httpaccess;
|
||||
|
||||
insert into host_web_ftpaccess (web,login) (select id,unnest(ftp) from host_web);
|
||||
ALTER TABLE host_web DROP ftp;
|
||||
|
||||
insert into host_mail_forward (mail,"to") (select id,unnest(forward) from host_mail);
|
||||
ALTER TABLE host_mail DROP forward;
|
||||
COMMIT;
|
||||
|
||||
```
|
||||
|
|
|
@ -24,9 +24,9 @@ func getMail(ctx context.Context, w http.ResponseWriter) (mail Mail, returnerr *
|
|||
return
|
||||
}
|
||||
if login.Superadmin {
|
||||
dbconnection.Where("id = ?", id).Find(&mail)
|
||||
dbconnection.Where("id = ?", id).Preload("Forwards").Find(&mail)
|
||||
} else {
|
||||
dbconnection.Where(map[string]int64{"ID": id, "domain.profil": profil.ID}).Find(&mail)
|
||||
dbconnection.Where(map[string]int64{"ID": id, "domain.profil": profil.ID}).Preload("Forwards").Find(&mail)
|
||||
}
|
||||
if mail.ID <= 0 {
|
||||
returnerr = &libapi.ErrorResult{Fields: []string{"mail"}, Message: "not found"}
|
||||
|
@ -44,7 +44,7 @@ func mailList(ctx context.Context, w http.ResponseWriter, r *http.Request) (retu
|
|||
logger.Info("not found")
|
||||
return
|
||||
}
|
||||
dbconnection.Where("domain = ?", domain.ID).Preload("Domain").Find(&mail)
|
||||
dbconnection.Where("domain = ?", domain.ID).Preload("Domain").Preload("Forwards").Find(&mail)
|
||||
logger.Info("done")
|
||||
returndata = mail
|
||||
return
|
||||
|
@ -69,7 +69,7 @@ func mailAdd(ctx context.Context, w http.ResponseWriter, r *http.Request) (retur
|
|||
mail := &Mail{
|
||||
DomainID: domain.ID,
|
||||
Name: mailRequest.Name,
|
||||
//Forward: mailRequest.Forward,
|
||||
Forwards: mailRequest.Forwards,
|
||||
LoginID: mailRequest.LoginID,
|
||||
}
|
||||
|
||||
|
@ -105,7 +105,7 @@ func mailEdit(ctx context.Context, w http.ResponseWriter, r *http.Request) (retu
|
|||
}
|
||||
|
||||
mail.Name = mailRequest.Name
|
||||
//mail.Forward = mailRequest.Forward
|
||||
mail.Forwards = mailRequest.Forwards
|
||||
mail.LoginID = mailRequest.LoginID
|
||||
|
||||
if err := dbconnection.Save(mail).Error; err != nil {
|
||||
|
|
|
@ -24,9 +24,9 @@ func getWeb(ctx context.Context, w http.ResponseWriter) (web Web, returnerr *lib
|
|||
return
|
||||
}
|
||||
if login.Superadmin {
|
||||
dbconnection.Where("id = ?", id).Find(&web)
|
||||
dbconnection.Where("id = ?", id).Preload("WebAccess.Login").Preload("FTPAccess.Login").Find(&web)
|
||||
} else {
|
||||
dbconnection.Where(map[string]int64{"ID": id, "domain.profil": profil.ID}).Find(&web)
|
||||
dbconnection.Where(map[string]int64{"ID": id, "domain.profil": profil.ID}).Preload("WebAccess.Login").Preload("FTPAccess.Login").Find(&web)
|
||||
}
|
||||
if web.ID <= 0 {
|
||||
returnerr = &libapi.ErrorResult{Fields: []string{"web"}, Message: "not found"}
|
||||
|
@ -44,7 +44,7 @@ func webList(ctx context.Context, w http.ResponseWriter, r *http.Request) (retur
|
|||
logger.Info("not found")
|
||||
return
|
||||
}
|
||||
dbconnection.Where("domain = ?", domain.ID).Preload("Domain").Find(&web)
|
||||
dbconnection.Where("domain = ?", domain.ID).Preload("Domain").Preload("WebAccess.Login").Preload("FTPAccess.Login").Find(&web)
|
||||
logger.Info("done")
|
||||
returndata = web
|
||||
return
|
||||
|
@ -74,8 +74,8 @@ func webAdd(ctx context.Context, w http.ResponseWriter, r *http.Request) (return
|
|||
SSLRedirect: webRequest.SSLRedirect,
|
||||
Redirect: webRequest.Redirect,
|
||||
Proxy: webRequest.Proxy,
|
||||
//FTP: webRequest.FTP,
|
||||
//HTTPAccess: webRequest.HTTPAccess,
|
||||
FTPAccess: webRequest.FTPAccess,
|
||||
WebAccess: webRequest.WebAccess,
|
||||
}
|
||||
|
||||
if err := dbconnection.Create(web).Error; err != nil {
|
||||
|
@ -115,8 +115,8 @@ func webEdit(ctx context.Context, w http.ResponseWriter, r *http.Request) (retur
|
|||
web.SSLRedirect = webRequest.SSLRedirect
|
||||
web.Redirect = webRequest.Redirect
|
||||
web.Proxy = webRequest.Proxy
|
||||
//web.FTP = webRequest.FTP
|
||||
//web.HTTPAccess = webRequest.HTTPAccess
|
||||
web.FTPAccess = webRequest.FTPAccess
|
||||
web.WebAccess = webRequest.WebAccess
|
||||
|
||||
if err := dbconnection.Save(web).Error; err != nil {
|
||||
logger.Error("database: during modify host web: ", err)
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package host
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
"dev.sum7.eu/sum7/warehost/system"
|
||||
|
@ -45,26 +43,59 @@ type Web struct {
|
|||
SSLRedirect bool `sql:"default:false;column:sslredirect" json:"sslredirect"`
|
||||
Redirect string `sql:"type:varchar(255);column:redirect" json:"redirect"`
|
||||
Proxy string `sql:"type:varchar(255);column:proxy" json:"proxy"`
|
||||
//FTP []int64 `sql:"type:bigint[];column:ftp" json:"ftp"`
|
||||
//HTTPAccess []int64 `sql:"type:bigint[];column:httpaccess" json:"httpaccess"`
|
||||
FTPAccess []*FTPAccess `json:"ftpaccess"`
|
||||
WebAccess []*WebAccess `json:"webaccess"`
|
||||
}
|
||||
|
||||
// TableName of struct
|
||||
func (Web) TableName() string { return "host_web" }
|
||||
|
||||
// FTPAccess is a Object which user has access by ftp on the data of this website
|
||||
type FTPAccess struct {
|
||||
WebID int64 `sql:"type:bigint NOT NULL REFERENCES host_web(id) ON UPDATE CASCADE ON DELETE CASCADE;column:web" json:"-"`
|
||||
Web *Web `gorm:"foreignkey:Web;unique_index:idx_host_domain_ftp_access" json:"web"`
|
||||
LoginID int64 `sql:"type:bigint NOT NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"-"`
|
||||
Login *system.Login `gorm:"foreignkey:Login;unique_index:idx_host_domain_ftp_access" json:"login"`
|
||||
}
|
||||
|
||||
// TableName of struct
|
||||
func (FTPAccess) TableName() string { return "host_web_ftpaccess" }
|
||||
|
||||
// WebAccess is a Object which user has access by httpaccess on the data of this website
|
||||
type WebAccess struct {
|
||||
WebID int64 `sql:"type:bigint NOT NULL REFERENCES host_web(id) ON UPDATE CASCADE ON DELETE CASCADE;column:web" json:"-"`
|
||||
Web *Web `gorm:"foreignkey:Web;unique_index:idx_host_domain_web_access" json:"web"`
|
||||
LoginID int64 `sql:"type:bigint NOT NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"-"`
|
||||
Login *system.Login `gorm:"foreignkey:Login;unique_index:idx_host_domain_web_access" json:"login"`
|
||||
}
|
||||
|
||||
// TableName of struct
|
||||
func (WebAccess) TableName() string { return "host_web_webaccess" }
|
||||
|
||||
// Mail struct
|
||||
type Mail struct {
|
||||
ID int64
|
||||
DomainID int64 `sql:"type:bigint NOT NULL REFERENCES host_domain(id) ON UPDATE CASCADE ON DELETE CASCADE;column:domain" json:"-"`
|
||||
Domain *Domain `gorm:"foreignkey:Domain;unique_index:idx_host_domain_mail" json:"domain"`
|
||||
Name string `sql:"type:varchar(255);column:name" gorm:"unique_index:idx_host_domain_mail" json:"name"`
|
||||
//Forward []string `sql:"type:varchar(255)[];column:forward" json:"forward"`
|
||||
LoginID sql.NullInt64 `sql:"type:bigint NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"login"`
|
||||
Forwards []*MailForward `json:"forwards"`
|
||||
LoginID *int64 `sql:"type:bigint NULL REFERENCES login(id) ON UPDATE CASCADE ON DELETE CASCADE;column:login" json:"login"`
|
||||
}
|
||||
|
||||
// TableName of struct
|
||||
func (Mail) TableName() string { return "host_mail" }
|
||||
|
||||
// MailForward is a Object on with address a copy of the mail should be send
|
||||
type MailForward struct {
|
||||
ID int64
|
||||
MailID int64 `sql:"type:bigint NOT NULL REFERENCES host_mail(id) ON UPDATE CASCADE ON DELETE CASCADE;column:mail" json:"-"`
|
||||
Mail *Mail `gorm:"foreignkey:Mail;unique_index:idx_host_domain_mail_forward" json:"mail"`
|
||||
To string `sql:"type:varchar(255);column:to" gorm:"unique_index:idx_host_domain_mail_forward" json:"to"`
|
||||
}
|
||||
|
||||
// TableName of struct
|
||||
func (MailForward) TableName() string { return "host_mail_forward" }
|
||||
|
||||
// Database struct
|
||||
type Database struct {
|
||||
ID int64
|
||||
|
@ -79,5 +110,5 @@ func (Database) TableName() string { return "host_database" }
|
|||
|
||||
// SyncModels to verify the database schema
|
||||
func SyncModels(dbconnection *gorm.DB) {
|
||||
dbconnection.AutoMigrate(&Profil{}, &Domain{}, &Web{}, &Mail{}, &Database{})
|
||||
dbconnection.AutoMigrate(&Profil{}, &Domain{}, &Web{}, &WebAccess{}, &FTPAccess{}, &Mail{}, &MailForward{}, &Database{})
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ func menuEdit(ctx context.Context, w http.ResponseWriter, r *http.Request) (retu
|
|||
menuEntry.ID = menuid
|
||||
|
||||
if err := dbconnection.Save(menuEntry).Error; err != nil {
|
||||
logger.Error("database: during delete website menu entry")
|
||||
logger.Error("database: during edit website menu entry")
|
||||
returnerr = &libapi.ErrorResult{Message: "Internal Database Error"}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package web
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/jinzhu/gorm"
|
||||
|
||||
system "dev.sum7.eu/sum7/warehost/system"
|
||||
|
@ -52,7 +51,7 @@ type Menu struct {
|
|||
WebsiteID int64 `sql:"type:bigint REFERENCES web_website(id) ON UPDATE CASCADE ON DELETE CASCADE;column:website" json:"-"`
|
||||
Name string `gorm:"type:varchar(255);column:name" json:"name"`
|
||||
Shorturl string `gorm:"type:varchar(255);column:url" json:"url"`
|
||||
ParentID sql.NullInt64 `sql:"type:bigint REFERENCES web_menu(id) ON UPDATE SET NULL ON DELETE SET NULL;column:menu" json:"parentid"`
|
||||
ParentID *int64 `sql:"type:bigint REFERENCES web_menu(id) ON UPDATE SET NULL ON DELETE SET NULL;column:menu" json:"parentid"`
|
||||
Position int `sql:"type:int;column:position" json:"position"`
|
||||
Children []*Menu `json:"children"`
|
||||
}
|
||||
|
@ -86,13 +85,13 @@ func BuildMenuTree(items []*Menu) []*Menu {
|
|||
menumap[item.ID] = item
|
||||
menumap[item.ID].Children = tmp
|
||||
}
|
||||
if !item.ParentID.Valid {
|
||||
if item.ParentID == nil {
|
||||
menuexit = append(menuexit, item)
|
||||
} else {
|
||||
if menumap[item.ParentID.Int64] == nil {
|
||||
menumap[item.ParentID.Int64] = &Menu{ID: -1}
|
||||
if menumap[*item.ParentID] == nil {
|
||||
menumap[*item.ParentID] = &Menu{ID: -1}
|
||||
}
|
||||
menumap[item.ParentID.Int64].Children = append(menumap[item.ParentID.Int64].Children, item)
|
||||
menumap[*item.ParentID].Children = append(menumap[*item.ParentID].Children, item)
|
||||
}
|
||||
}
|
||||
return menuexit
|
||||
|
|
Reference in New Issue