Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for /api/admin/users/:id/permissions endpoint #37

Merged
merged 2 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions rest-admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ func (r *Client) CreateUser(user User) (StatusMessage, error) {
return resp, nil
}

// UpdateUserPermissions updates the permissions of a global user
// Only work with Basic Authentication
// It reflects PUT /api/admin/users/:userId/permissions
func (r *Client) UpdateUserPermissions(permissions UserPermissions, uid uint) (StatusMessage, error) {
var (
raw []byte
reply StatusMessage
err error
)
if raw, err = json.Marshal(permissions); err != nil {
return StatusMessage{}, err
}
if raw, _, err = r.put(fmt.Sprintf("api/admin/users/%d/permissions", uid), nil, raw); err != nil {
return StatusMessage{}, err
}
err = json.Unmarshal(raw, &reply)
return reply, err
}

func (r *Client) SwitchUserContext(uid uint, oid uint) (StatusMessage, error) {
var (
raw []byte
Expand Down
4 changes: 4 additions & 0 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type UserRole struct {
Role string `json:"role"`
}

type UserPermissions struct {
IsGrafanaAdmin bool `json:"isGrafanaAdmin"`
}

type PageUsers struct {
TotalCount int `json:"totalCount"`
Users []User `json:"users"`
Expand Down