71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
package web
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"goji.io/pat"
|
|
"golang.org/x/net/context"
|
|
|
|
libapi "dev.sum7.eu/sum7/warehost/lib/api"
|
|
)
|
|
|
|
// PermissionList to add permissions
|
|
func permissionList(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
|
returndata = false
|
|
logger := log.GetLog(r, "permissionlist")
|
|
var involved []*Manager
|
|
dbconnection.Where("website = ?", ctx.Value("websiteid").(int64)).Preload("Login").Find(&involved)
|
|
logger.Info("done")
|
|
returndata = involved
|
|
return
|
|
}
|
|
|
|
// PermissionAdd to add permissions
|
|
func permissionAdd(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
|
returndata = false
|
|
logger := log.GetLog(r, "permissionadd")
|
|
loginid, err := strconv.ParseInt(pat.Param(ctx, "loginid"), 10, 64)
|
|
if err != nil {
|
|
returnerr = &libapi.ErrorResult{Fields: []string{"loginid"}, Message: "Not a valid loginid"}
|
|
logger.Warn("invalid loginid, no integer")
|
|
return
|
|
}
|
|
manager := &Manager{
|
|
WebsiteID: ctx.Value("websiteid").(int64),
|
|
LoginID: loginid,
|
|
}
|
|
if err := dbconnection.Create(manager).Error; err != nil {
|
|
logger.Error("database: during create website permission")
|
|
returnerr = &libapi.ErrorResult{Message: "Internal Database Error"}
|
|
return
|
|
}
|
|
returndata = true
|
|
logger.Info("done")
|
|
return
|
|
}
|
|
|
|
// PermissionDelete to delete permissions
|
|
func permissionDelete(ctx context.Context, w http.ResponseWriter, r *http.Request) (returndata interface{}, returnerr *libapi.ErrorResult) {
|
|
returndata = false
|
|
logger := log.GetLog(r, "permissiondelete")
|
|
loginid, err := strconv.ParseInt(pat.Param(ctx, "loginid"), 10, 64)
|
|
if err != nil {
|
|
returnerr = &libapi.ErrorResult{Fields: []string{"loginid"}, Message: "Not a valid loginid"}
|
|
logger.Warn("invalid loginid, no integer")
|
|
return
|
|
}
|
|
manager := &Manager{
|
|
WebsiteID: ctx.Value("websiteid").(int64),
|
|
LoginID: loginid,
|
|
}
|
|
if err := dbconnection.Unscoped().Delete(manager).Error; err != nil {
|
|
logger.Error("database: during delete website permission")
|
|
returnerr = &libapi.ErrorResult{Message: "Internal Database Error"}
|
|
return
|
|
}
|
|
returndata = true
|
|
logger.Info("done")
|
|
return
|
|
}
|