feat(admin): enable multi-users (#67)
* feat(userstore): support ListUsers * feat(userstore): support del users * feat(multiusers): support list users and delete user apis * feat(client/web): add new apis to web client * fix(ui/panes): move each pane out of the container * feat(ui): add admin pane * feat(users): support force set password api * feat(ui/admin-pane): add functions to admin pane * feat(users): support self API and move uploading folder to home * fix(users): remove home folder when deleting user * fix(ui): remove useless function * feat(ui/panes): hide admin menu if user is not admin * fix(server/files): list home path is incorrect * fix(server): 1.listHome return incorrect cwd 2.addUser init folder with incorrect uid 3.check ns before using * test(server): add regression test cases * test(users, files): add e2e test for concurrent operations * fix(test): clean ups
This commit is contained in:
parent
916ec7c2dc
commit
aefaca98b3
28 changed files with 1562 additions and 478 deletions
|
@ -1,110 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/ihexxa/quickshare/src/handlers/multiusers"
|
||||
"github.com/parnurzeal/gorequest"
|
||||
)
|
||||
|
||||
type SingleUserClient struct {
|
||||
addr string
|
||||
r *gorequest.SuperAgent
|
||||
}
|
||||
|
||||
func NewSingleUserClient(addr string) *SingleUserClient {
|
||||
gr := gorequest.New()
|
||||
return &SingleUserClient{
|
||||
addr: addr,
|
||||
r: gr,
|
||||
}
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) url(urlpath string) string {
|
||||
return fmt.Sprintf("%s%s", cl.addr, urlpath)
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) Login(user, pwd string) (*http.Response, string, []error) {
|
||||
return cl.r.Post(cl.url("/v1/users/login")).
|
||||
Send(multiusers.LoginReq{
|
||||
User: user,
|
||||
Pwd: pwd,
|
||||
}).
|
||||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) Logout(token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Post(cl.url("/v1/users/logout")).
|
||||
AddCookie(token).
|
||||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) SetPwd(oldPwd, newPwd string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Patch(cl.url("/v1/users/pwd")).
|
||||
Send(multiusers.SetPwdReq{
|
||||
OldPwd: oldPwd,
|
||||
NewPwd: newPwd,
|
||||
}).
|
||||
AddCookie(token).
|
||||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) AddUser(name, pwd, role string, token *http.Cookie) (*http.Response, *multiusers.AddUserResp, []error) {
|
||||
resp, body, errs := cl.r.Post(cl.url("/v1/users/")).
|
||||
AddCookie(token).
|
||||
Send(multiusers.AddUserReq{
|
||||
Name: name,
|
||||
Pwd: pwd,
|
||||
Role: role,
|
||||
}).
|
||||
End()
|
||||
|
||||
if len(errs) > 0 {
|
||||
return nil, nil, errs
|
||||
}
|
||||
|
||||
auResp := &multiusers.AddUserResp{}
|
||||
err := json.Unmarshal([]byte(body), auResp)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
return nil, nil, errs
|
||||
}
|
||||
return resp, auResp, errs
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) AddRole(role string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Post(cl.url("/v1/roles/")).
|
||||
AddCookie(token).
|
||||
Send(multiusers.AddRoleReq{
|
||||
Role: role,
|
||||
}).
|
||||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) DelRole(role string, token *http.Cookie) (*http.Response, string, []error) {
|
||||
return cl.r.Delete(cl.url("/v1/roles/")).
|
||||
AddCookie(token).
|
||||
Send(multiusers.DelRoleReq{
|
||||
Role: role,
|
||||
}).
|
||||
End()
|
||||
}
|
||||
|
||||
func (cl *SingleUserClient) ListRoles(token *http.Cookie) (*http.Response, *multiusers.ListRolesResp, []error) {
|
||||
resp, body, errs := cl.r.Get(cl.url("/v1/roles/")).
|
||||
AddCookie(token).
|
||||
End()
|
||||
if len(errs) > 0 {
|
||||
return nil, nil, errs
|
||||
}
|
||||
|
||||
lsResp := &multiusers.ListRolesResp{}
|
||||
err := json.Unmarshal([]byte(body), lsResp)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
return nil, nil, errs
|
||||
}
|
||||
return resp, lsResp, errs
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue