summaryrefslogtreecommitdiffstats
path: root/model/user.go
diff options
context:
space:
mode:
authorChris Duarte <csduarte@users.noreply.github.com>2018-01-04 09:45:59 -0800
committerJoram Wilander <jwawilander@gmail.com>2018-01-04 12:45:59 -0500
commit5e78d7fe12a39e28a6520b023b0df0fc66a826d5 (patch)
treed4eacf4c02f5300917093efc13e73f9761c7756c /model/user.go
parente5dad3cf681fb038ce5dd3dcf7b5468d59b8ea8e (diff)
downloadchat-5e78d7fe12a39e28a6520b023b0df0fc66a826d5.tar.gz
chat-5e78d7fe12a39e28a6520b023b0df0fc66a826d5.tar.bz2
chat-5e78d7fe12a39e28a6520b023b0df0fc66a826d5.zip
Add admin update endpoint that can update authservice and authdata (#7842)
* add admin update endpoint that can upate authservice and authdata * Control only SystemAdmin access * Refactored AdminUpdate endpoint to only be able to update AuthData, AuthService and Password by User.Id * Refactor to move `PUT /api/v4/users/{user_id}/auth`. Created a struct to hold UserAuth info.
Diffstat (limited to 'model/user.go')
-rw-r--r--model/user.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/model/user.go b/model/user.go
index 8d8c76c68..7e767fd5c 100644
--- a/model/user.go
+++ b/model/user.go
@@ -88,6 +88,12 @@ type UserPatch struct {
Locale *string `json:"locale"`
}
+type UserAuth struct {
+ Password string `json:"password,omitempty"`
+ AuthData *string `json:"auth_data,omitempty"`
+ AuthService string `json:"auth_service,omitempty"`
+}
+
// IsValid validates the user and returns an error if it isn't configured
// correctly.
func (u *User) IsValid() *AppError {
@@ -309,6 +315,15 @@ func (u *UserPatch) ToJson() string {
}
}
+func (u *UserAuth) ToJson() string {
+ b, err := json.Marshal(u)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
// Generate a valid strong etag so the browser can cache the results
func (u *User) Etag(showFullName, showEmail bool) string {
return Etag(u.Id, u.UpdateAt, showFullName, showEmail)
@@ -494,6 +509,17 @@ func UserPatchFromJson(data io.Reader) *UserPatch {
}
}
+func UserAuthFromJson(data io.Reader) *UserAuth {
+ decoder := json.NewDecoder(data)
+ var user UserAuth
+ err := decoder.Decode(&user)
+ if err == nil {
+ return &user
+ } else {
+ return nil
+ }
+}
+
func UserMapToJson(u map[string]*User) string {
b, err := json.Marshal(u)
if err != nil {