浏览代码

list of peole works, user enabled move to people

master
sp 4 年前
父节点
当前提交
a7e77ed1bf
共有 6 个文件被更改,包括 39 次插入12 次删除
  1. +3
    -0
      apiV1Avatar.go
  2. +0
    -2
      apiV1BrokerList.go
  3. +1
    -3
      apiV1PeopleList.go
  4. +33
    -4
      apiV1User.go
  5. +0
    -3
      apiV1login.go
  6. +2
    -0
      apiv1.go

+ 3
- 0
apiV1Avatar.go 查看文件

@@ -70,6 +70,9 @@ func apiV1Avatar(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
avatar = defaultAvatar // production mode
}
}
if avatar == "" { // to prevent empty avatar in case of db error
avatar = defaultAvatar
}

// Data is the base64 encoded image
// The actual image starts after the ","

+ 0
- 2
apiV1BrokerList.go 查看文件

@@ -51,7 +51,6 @@ func apiV1BrokerDelete(w http.ResponseWriter, r *http.Request, ss *loan.Session)

ue := UserExtra{}
ue.Login = ""
ue.Enabled = false
ue.License = ""
ue.Organization = ""
ue.BSB = ""
@@ -95,7 +94,6 @@ func apiV1BrokerPut(w http.ResponseWriter, r *http.Request, ss *loan.Session) {

ue := UserExtra{}
ue.Login = b.Login
ue.Enabled = b.Enabled
ue.Role = "broker"
ue.License = b.License
ue.Organization = b.Organization

+ 1
- 3
apiV1PeopleList.go 查看文件

@@ -62,6 +62,7 @@ func apiV1PeoplePost(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
p.First = input.First
p.Last = input.Last
p.Display = input.Display
p.Enabled = input.Enabled

if ss.GetRole() == "admin" {
p.Title = input.Title
@@ -116,7 +117,6 @@ func apiV1PeopleExtraGet(w http.ResponseWriter, r *http.Request, ss *loan.Sessio
u := loan.User{}
e := u.Read(id)
ret.Login = u.Login
ret.Enabled = u.Enabled

if e != nil {
log.Error("cannot find user by id", id)
@@ -138,7 +138,6 @@ func apiV1PeopleExtraGet(w http.ResponseWriter, r *http.Request, ss *loan.Sessio
return
}
ret.Login = b.Login
ret.Enabled = b.Enabled
ret.BSB = b.BSB
ret.ACC = b.ACC
ret.Organization = b.Organization
@@ -149,7 +148,6 @@ func apiV1PeopleExtraGet(w http.ResponseWriter, r *http.Request, ss *loan.Sessio
u := loan.User{}
e := u.Read(id)
ret.Login = u.Login
ret.Enabled = u.Enabled

if e != nil {
log.Error("cannot find admin by id", id)

+ 33
- 4
apiV1User.go 查看文件

@@ -5,11 +5,11 @@ import (
"encoding/json"
"github.com/brianvoe/gofakeit/v6"
log "github.com/sirupsen/logrus"
"io/ioutil"
"net/http"
)

type UserExtra struct {
Enabled bool
Login string
BSB string
ACC string
@@ -57,7 +57,6 @@ func apiV1UserPut(w http.ResponseWriter, r *http.Request, ss *loan.Session) {

ue := UserExtra{}
ue.Login = u.Login
ue.Enabled = u.Enabled
ue.Role = "user"
ue.License = ""
ue.Organization = ""
@@ -83,7 +82,6 @@ func apiV1UserDelete(w http.ResponseWriter, r *http.Request, ss *loan.Session) {

ue := UserExtra{}
ue.Login = ""
ue.Enabled = false
ue.Role = "people"
ue.License = ""
ue.Organization = ""
@@ -110,7 +108,6 @@ func apiV1UserPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
return
}

u.Enabled = input.Enabled
u.Login = input.Login

e = u.Write()
@@ -122,3 +119,35 @@ func apiV1UserPost(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
}
}
}

func apiV1UserEnable(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
id := r.URL.Path[len(apiV1Prefix+"user-enable/"):] //remove prefix
p := loan.People{}

body, e := ioutil.ReadAll(r.Body)
if e != nil {
log.Error("invalid request body for enable/disable people ", id, " err= ", e.Error())
apiV1Client403Error(w, r, ss)
return
}

e = p.Read(id)
if e != nil {
log.Error("failed to read user by id ", id, e.Error())
apiV1Client403Error(w, r, ss)
return
}

p.Enabled = string(body) == "true"
if id == "0" {
p.Enabled = true
} // can not disable default admin

e = p.Write()
if e != nil {
log.Error("failed to enable user ", id, e.Error())
apiV1Client403Error(w, r, ss)
return
}
apiV1SendJson(p.Enabled, w, r, ss)
}

+ 0
- 3
apiV1login.go 查看文件

@@ -77,7 +77,6 @@ func apiV1Login(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
func getUserExtraForLogin(u loan.User, ss *loan.Session) (ret UserExtra) {
if ss.GetRole() == "user" {
ret = UserExtra{
Enabled: true,
Login: u.Login,
BSB: "",
ACC: "",
@@ -94,7 +93,6 @@ func getUserExtraForLogin(u loan.User, ss *loan.Session) (ret UserExtra) {
log.Error("fail to retrieve broker for session ", ss, e.Error())
} else {
ret = UserExtra{
Enabled: broker.Enabled,
Login: broker.Login,
BSB: broker.BSB,
ACC: broker.ACC,
@@ -107,7 +105,6 @@ func getUserExtraForLogin(u loan.User, ss *loan.Session) (ret UserExtra) {

if ss.GetRole() == "admin" {
ret = UserExtra{
Enabled: true,
Login: u.Login,
BSB: "",
ACC: "",

+ 2
- 0
apiv1.go 查看文件

@@ -50,6 +50,7 @@ func setupApiV1Handler() []apiV1HandlerMap {
{"POST", "user/", apiV1UserPost},
{"PUT", "user/", apiV1UserPut},
{"DELETE", "user/", apiV1UserDelete},
{"POST", "user-enable/", apiV1UserEnable},

{"GET", "broker/", apiV1BrokerGet},
{"POST", "broker/", apiV1BrokerPost},
@@ -95,6 +96,7 @@ func setupApiV1Handler() []apiV1HandlerMap {
{"POST", "user/", apiV1UserPost},
{"PUT", "user/", apiV1UserPut},
{"DELETE", "user/", apiV1UserDelete},
{"POST", "user-enable/", apiV1UserEnable},

{"GET", "broker/", apiV1BrokerGet},
{"POST", "broker/", apiV1BrokerPost},

正在加载...
取消
保存