mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-07-05 03:34:03 +00:00
Update vendor (#1265)
This commit is contained in:
573
vendor/github.com/mattermost/mattermost-server/v5/model/client4.go
generated
vendored
573
vendor/github.com/mattermost/mattermost-server/v5/model/client4.go
generated
vendored
@ -10,6 +10,7 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@ -61,6 +62,40 @@ type Client4 struct {
|
||||
AuthToken string
|
||||
AuthType string
|
||||
HttpHeader map[string]string // Headers to be copied over for each request
|
||||
|
||||
// TrueString is the string value sent to the server for true boolean query parameters.
|
||||
trueString string
|
||||
|
||||
// FalseString is the string value sent to the server for false boolean query parameters.
|
||||
falseString string
|
||||
}
|
||||
|
||||
// SetBoolString is a helper method for overriding how true and false query string parameters are
|
||||
// sent to the server.
|
||||
//
|
||||
// This method is only exposed for testing. It is never necessary to configure these values
|
||||
// in production.
|
||||
func (c *Client4) SetBoolString(value bool, valueStr string) {
|
||||
if value {
|
||||
c.trueString = valueStr
|
||||
} else {
|
||||
c.falseString = valueStr
|
||||
}
|
||||
}
|
||||
|
||||
// boolString builds the query string parameter for boolean values.
|
||||
func (c *Client4) boolString(value bool) string {
|
||||
if value && c.trueString != "" {
|
||||
return c.trueString
|
||||
} else if !value && c.falseString != "" {
|
||||
return c.falseString
|
||||
}
|
||||
|
||||
if value {
|
||||
return "true"
|
||||
} else {
|
||||
return "false"
|
||||
}
|
||||
}
|
||||
|
||||
func closeBody(r *http.Response) {
|
||||
@ -81,7 +116,21 @@ func (c *Client4) Must(result interface{}, resp *Response) interface{} {
|
||||
}
|
||||
|
||||
func NewAPIv4Client(url string) *Client4 {
|
||||
return &Client4{url, url + API_URL_SUFFIX, &http.Client{}, "", "", map[string]string{}}
|
||||
url = strings.TrimRight(url, "/")
|
||||
return &Client4{url, url + API_URL_SUFFIX, &http.Client{}, "", "", map[string]string{}, "", ""}
|
||||
}
|
||||
|
||||
func NewAPIv4SocketClient(socketPath string) *Client4 {
|
||||
tr := &http.Transport{
|
||||
Dial: func(network, addr string) (net.Conn, error) {
|
||||
return net.Dial("unix", socketPath)
|
||||
},
|
||||
}
|
||||
|
||||
client := NewAPIv4Client("http://_")
|
||||
client.HttpClient = &http.Client{Transport: tr}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
func BuildErrorResponse(r *http.Response, err *AppError) *Response {
|
||||
@ -140,6 +189,10 @@ func (c *Client4) GetUserRoute(userId string) string {
|
||||
return fmt.Sprintf(c.GetUsersRoute()+"/%v", userId)
|
||||
}
|
||||
|
||||
func (c *Client4) GetUserCategoryRoute(userID, teamID string) string {
|
||||
return c.GetUserRoute(userID) + c.GetTeamRoute(teamID) + "/channels/categories"
|
||||
}
|
||||
|
||||
func (c *Client4) GetUserAccessTokensRoute() string {
|
||||
return fmt.Sprintf(c.GetUsersRoute() + "/tokens")
|
||||
}
|
||||
@ -261,6 +314,14 @@ func (c *Client4) GetFileRoute(fileId string) string {
|
||||
return fmt.Sprintf(c.GetFilesRoute()+"/%v", fileId)
|
||||
}
|
||||
|
||||
func (c *Client4) GetUploadsRoute() string {
|
||||
return "/uploads"
|
||||
}
|
||||
|
||||
func (c *Client4) GetUploadRoute(uploadId string) string {
|
||||
return fmt.Sprintf("%s/%s", c.GetUploadsRoute(), uploadId)
|
||||
}
|
||||
|
||||
func (c *Client4) GetPluginsRoute() string {
|
||||
return "/plugins"
|
||||
}
|
||||
@ -453,6 +514,10 @@ func (c *Client4) GetGroupsRoute() string {
|
||||
return "/groups"
|
||||
}
|
||||
|
||||
func (c *Client4) GetPublishUserTypingRoute(userId string) string {
|
||||
return c.GetUserRoute(userId) + "/typing"
|
||||
}
|
||||
|
||||
func (c *Client4) GetGroupRoute(groupID string) string {
|
||||
return fmt.Sprintf("%s/%s", c.GetGroupsRoute(), groupID)
|
||||
}
|
||||
@ -650,7 +715,7 @@ func (c *Client4) LoginByLdap(loginId string, password string) (*User, *Response
|
||||
m := make(map[string]string)
|
||||
m["login_id"] = loginId
|
||||
m["password"] = password
|
||||
m["ldap_only"] = "true"
|
||||
m["ldap_only"] = c.boolString(true)
|
||||
return c.login(m)
|
||||
}
|
||||
|
||||
@ -967,6 +1032,17 @@ func (c *Client4) GetUsersWithoutTeam(page int, perPage int, etag string) ([]*Us
|
||||
return UserListFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// GetUsersInGroup returns a page of users in a group. Page counting starts at 0.
|
||||
func (c *Client4) GetUsersInGroup(groupID string, page int, perPage int, etag string) ([]*User, *Response) {
|
||||
query := fmt.Sprintf("?in_group=%v&page=%v&per_page=%v", groupID, page, perPage)
|
||||
r, err := c.DoApiGet(c.GetUsersRoute()+query, etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return UserListFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// GetUsersByIds returns a list of users based on the provided user ids.
|
||||
func (c *Client4) GetUsersByIds(userIds []string) ([]*User, *Response) {
|
||||
r, err := c.DoApiPost(c.GetUsersRoute()+"/ids", ArrayToJson(userIds))
|
||||
@ -1119,6 +1195,17 @@ func (c *Client4) UpdateUserPassword(userId, currentPassword, newPassword string
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// UpdateUserHashedPassword updates a user's password with an already-hashed password. Must be a system administrator.
|
||||
func (c *Client4) UpdateUserHashedPassword(userId, newHashedPassword string) (bool, *Response) {
|
||||
requestBody := map[string]string{"already_hashed": "true", "new_password": newHashedPassword}
|
||||
r, err := c.DoApiPut(c.GetUserRoute(userId)+"/password", MapToJson(requestBody))
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// PromoteGuestToUser convert a guest into a regular user
|
||||
func (c *Client4) PromoteGuestToUser(guestId string) (bool, *Response) {
|
||||
r, err := c.DoApiPost(c.GetUserRoute(guestId)+"/promote", "")
|
||||
@ -1173,6 +1260,50 @@ func (c *Client4) DeleteUser(userId string) (bool, *Response) {
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// PermanentDeleteUser deletes a user in the system based on the provided user id string.
|
||||
func (c *Client4) PermanentDeleteUser(userId string) (bool, *Response) {
|
||||
r, err := c.DoApiDelete(c.GetUserRoute(userId) + "?permanent=" + c.boolString(true))
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// ConvertUserToBot converts a user to a bot user.
|
||||
func (c *Client4) ConvertUserToBot(userId string) (*Bot, *Response) {
|
||||
r, err := c.DoApiPost(c.GetUserRoute(userId)+"/convert_to_bot", "")
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return BotFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// ConvertBotToUser converts a bot user to a user.
|
||||
func (c *Client4) ConvertBotToUser(userId string, userPatch *UserPatch, setSystemAdmin bool) (*User, *Response) {
|
||||
var query string
|
||||
if setSystemAdmin {
|
||||
query = "?set_system_admin=true"
|
||||
}
|
||||
r, err := c.DoApiPost(c.GetBotRoute(userId)+"/convert_to_user"+query, userPatch.ToJson())
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return UserFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// PermanentDeleteAll permanently deletes all users in the system. This is a local only endpoint
|
||||
func (c *Client4) PermanentDeleteAllUsers() (bool, *Response) {
|
||||
r, err := c.DoApiDelete(c.GetUsersRoute())
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// SendPasswordResetEmail will send a link for password resetting to a user with the
|
||||
// provided email.
|
||||
func (c *Client4) SendPasswordResetEmail(email string) (bool, *Response) {
|
||||
@ -1287,6 +1418,16 @@ func (c *Client4) VerifyUserEmail(token string) (bool, *Response) {
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// VerifyUserEmailWithoutToken will verify a user's email by its Id. (Requires manage system role)
|
||||
func (c *Client4) VerifyUserEmailWithoutToken(userId string) (*User, *Response) {
|
||||
r, err := c.DoApiPost(c.GetUserRoute(userId)+"/email/verify/member", "")
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return UserFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// SendVerificationEmail will send an email to the user with the provided email address, if
|
||||
// that user exists. The email will contain a link that can be used to verify the user's
|
||||
// email address.
|
||||
@ -1487,7 +1628,7 @@ func (c *Client4) GetBot(userId string, etag string) (*Bot, *Response) {
|
||||
|
||||
// GetBot fetches the given bot, even if it is deleted.
|
||||
func (c *Client4) GetBotIncludeDeleted(userId string, etag string) (*Bot, *Response) {
|
||||
r, err := c.DoApiGet(c.GetBotRoute(userId)+"?include_deleted=true", etag)
|
||||
r, err := c.DoApiGet(c.GetBotRoute(userId)+"?include_deleted="+c.boolString(true), etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
@ -1508,7 +1649,7 @@ func (c *Client4) GetBots(page, perPage int, etag string) ([]*Bot, *Response) {
|
||||
|
||||
// GetBotsIncludeDeleted fetches the given page of bots, including deleted.
|
||||
func (c *Client4) GetBotsIncludeDeleted(page, perPage int, etag string) ([]*Bot, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&include_deleted=true", page, perPage)
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&include_deleted="+c.boolString(true), page, perPage)
|
||||
r, err := c.DoApiGet(c.GetBotsRoute()+query, etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
@ -1519,7 +1660,7 @@ func (c *Client4) GetBotsIncludeDeleted(page, perPage int, etag string) ([]*Bot,
|
||||
|
||||
// GetBotsOrphaned fetches the given page of bots, only including orphanded bots.
|
||||
func (c *Client4) GetBotsOrphaned(page, perPage int, etag string) ([]*Bot, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&only_orphaned=true", page, perPage)
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&only_orphaned="+c.boolString(true), page, perPage)
|
||||
r, err := c.DoApiGet(c.GetBotsRoute()+query, etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
@ -1659,7 +1800,7 @@ func (c *Client4) GetAllTeams(etag string, page int, perPage int) ([]*Team, *Res
|
||||
|
||||
// GetAllTeamsWithTotalCount returns all teams based on permissions.
|
||||
func (c *Client4) GetAllTeamsWithTotalCount(etag string, page int, perPage int) ([]*Team, int64, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&include_total_count=true", page, perPage)
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&include_total_count="+c.boolString(true), page, perPage)
|
||||
r, err := c.DoApiGet(c.GetTeamsRoute()+query, etag)
|
||||
if err != nil {
|
||||
return nil, 0, BuildErrorResponse(r, err)
|
||||
@ -1811,7 +1952,7 @@ func (c *Client4) SoftDeleteTeam(teamId string) (bool, *Response) {
|
||||
// PermanentDeleteTeam deletes the team, should only be used when needed for
|
||||
// compliance and the like.
|
||||
func (c *Client4) PermanentDeleteTeam(teamId string) (bool, *Response) {
|
||||
r, err := c.DoApiDelete(c.GetTeamRoute(teamId) + "?permanent=true")
|
||||
r, err := c.DoApiDelete(c.GetTeamRoute(teamId) + "?permanent=" + c.boolString(true))
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
@ -1931,7 +2072,7 @@ func (c *Client4) AddTeamMembersGracefully(teamId string, userIds []string) ([]*
|
||||
members = append(members, member)
|
||||
}
|
||||
|
||||
r, err := c.DoApiPost(c.GetTeamMembersRoute(teamId)+"/batch?graceful=true", TeamMembersToJson(members))
|
||||
r, err := c.DoApiPost(c.GetTeamMembersRoute(teamId)+"/batch?graceful="+c.boolString(true), TeamMembersToJson(members))
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
@ -2049,7 +2190,7 @@ func (c *Client4) InviteGuestsToTeam(teamId string, userEmails []string, channel
|
||||
|
||||
// InviteUsersToTeam invite users by email to the team.
|
||||
func (c *Client4) InviteUsersToTeamGracefully(teamId string, userEmails []string) ([]*EmailInviteWithError, *Response) {
|
||||
r, err := c.DoApiPost(c.GetTeamRoute(teamId)+"/invite/email?graceful=true", ArrayToJson(userEmails))
|
||||
r, err := c.DoApiPost(c.GetTeamRoute(teamId)+"/invite/email?graceful="+c.boolString(true), ArrayToJson(userEmails))
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
@ -2064,7 +2205,7 @@ func (c *Client4) InviteGuestsToTeamGracefully(teamId string, userEmails []strin
|
||||
Channels: channels,
|
||||
Message: message,
|
||||
}
|
||||
r, err := c.DoApiPost(c.GetTeamRoute(teamId)+"/invite-guests/email?graceful=true", guestsInvite.ToJson())
|
||||
r, err := c.DoApiPost(c.GetTeamRoute(teamId)+"/invite-guests/email?graceful="+c.boolString(true), guestsInvite.ToJson())
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
@ -2163,7 +2304,16 @@ func (c *Client4) RemoveTeamIcon(teamId string) (bool, *Response) {
|
||||
|
||||
// GetAllChannels get all the channels. Must be a system administrator.
|
||||
func (c *Client4) GetAllChannels(page int, perPage int, etag string) (*ChannelListWithTeamData, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
|
||||
return c.getAllChannels(page, perPage, etag, false)
|
||||
}
|
||||
|
||||
// GetAllChannelsIncludeDeleted get all the channels. Must be a system administrator.
|
||||
func (c *Client4) GetAllChannelsIncludeDeleted(page int, perPage int, etag string) (*ChannelListWithTeamData, *Response) {
|
||||
return c.getAllChannels(page, perPage, etag, true)
|
||||
}
|
||||
|
||||
func (c *Client4) getAllChannels(page int, perPage int, etag string, includeDeleted bool) (*ChannelListWithTeamData, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&include_deleted=%v", page, perPage, includeDeleted)
|
||||
r, err := c.DoApiGet(c.GetChannelsRoute()+query, etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
@ -2174,7 +2324,7 @@ func (c *Client4) GetAllChannels(page int, perPage int, etag string) (*ChannelLi
|
||||
|
||||
// GetAllChannelsWithCount get all the channels including the total count. Must be a system administrator.
|
||||
func (c *Client4) GetAllChannelsWithCount(page int, perPage int, etag string) (*ChannelListWithTeamData, int64, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&include_total_count=true", page, perPage)
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&include_total_count="+c.boolString(true), page, perPage)
|
||||
r, err := c.DoApiGet(c.GetChannelsRoute()+query, etag)
|
||||
if err != nil {
|
||||
return nil, 0, BuildErrorResponse(r, err)
|
||||
@ -2307,6 +2457,17 @@ func (c *Client4) GetPinnedPosts(channelId string, etag string) (*PostList, *Res
|
||||
return PostListFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// GetPrivateChannelsForTeam returns a list of private channels based on the provided team id string.
|
||||
func (c *Client4) GetPrivateChannelsForTeam(teamId string, page int, perPage int, etag string) ([]*Channel, *Response) {
|
||||
query := fmt.Sprintf("/private?page=%v&per_page=%v", page, perPage)
|
||||
r, err := c.DoApiGet(c.GetChannelsForTeamRoute(teamId)+query, etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return ChannelSliceFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// GetPublicChannelsForTeam returns a list of public channels based on the provided team id string.
|
||||
func (c *Client4) GetPublicChannelsForTeam(teamId string, page int, perPage int, etag string) ([]*Channel, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
|
||||
@ -2349,6 +2510,18 @@ func (c *Client4) GetChannelsForTeamForUser(teamId, userId string, includeDelete
|
||||
return ChannelSliceFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// GetChannelsForTeamAndUserWithLastDeleteAt returns a list channels of a team for a user, additionally filtered with lastDeleteAt. This does not have any effect if includeDeleted is set to false.
|
||||
func (c *Client4) GetChannelsForTeamAndUserWithLastDeleteAt(teamId, userId string, includeDeleted bool, lastDeleteAt int, etag string) ([]*Channel, *Response) {
|
||||
route := fmt.Sprintf(c.GetUserRoute(userId) + c.GetTeamRoute(teamId) + "/channels")
|
||||
route += fmt.Sprintf("?include_deleted=%v&last_delete_at=%d", includeDeleted, lastDeleteAt)
|
||||
r, err := c.DoApiGet(route, etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return ChannelSliceFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// SearchChannels returns the channels on a team matching the provided search term.
|
||||
func (c *Client4) SearchChannels(teamId string, search *ChannelSearch) ([]*Channel, *Response) {
|
||||
r, err := c.DoApiPost(c.GetChannelsForTeamRoute(teamId)+"/search", search.ToJson())
|
||||
@ -2409,6 +2582,30 @@ func (c *Client4) DeleteChannel(channelId string) (bool, *Response) {
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// PermanentDeleteChannel deletes a channel based on the provided channel id string.
|
||||
func (c *Client4) PermanentDeleteChannel(channelId string) (bool, *Response) {
|
||||
r, err := c.DoApiDelete(c.GetChannelRoute(channelId) + "?permanent=" + c.boolString(true))
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// MoveChannel moves the channel to the destination team.
|
||||
func (c *Client4) MoveChannel(channelId, teamId string, force bool) (*Channel, *Response) {
|
||||
requestBody := map[string]interface{}{
|
||||
"team_id": teamId,
|
||||
"force": force,
|
||||
}
|
||||
r, err := c.DoApiPost(c.GetChannelRoute(channelId)+"/move", StringInterfaceToJson(requestBody))
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return ChannelFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// GetChannelByName returns a channel based on the provided channel name and team id strings.
|
||||
func (c *Client4) GetChannelByName(channelName, teamId string, etag string) (*Channel, *Response) {
|
||||
r, err := c.DoApiGet(c.GetChannelByNameRoute(channelName, teamId), etag)
|
||||
@ -2421,7 +2618,7 @@ func (c *Client4) GetChannelByName(channelName, teamId string, etag string) (*Ch
|
||||
|
||||
// GetChannelByNameIncludeDeleted returns a channel based on the provided channel name and team id strings. Other then GetChannelByName it will also return deleted channels.
|
||||
func (c *Client4) GetChannelByNameIncludeDeleted(channelName, teamId string, etag string) (*Channel, *Response) {
|
||||
r, err := c.DoApiGet(c.GetChannelByNameRoute(channelName, teamId)+"?include_deleted=true", etag)
|
||||
r, err := c.DoApiGet(c.GetChannelByNameRoute(channelName, teamId)+"?include_deleted="+c.boolString(true), etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
@ -2441,7 +2638,7 @@ func (c *Client4) GetChannelByNameForTeamName(channelName, teamName string, etag
|
||||
|
||||
// GetChannelByNameForTeamNameIncludeDeleted returns a channel based on the provided channel name and team name strings. Other then GetChannelByNameForTeamName it will also return deleted channels.
|
||||
func (c *Client4) GetChannelByNameForTeamNameIncludeDeleted(channelName, teamName string, etag string) (*Channel, *Response) {
|
||||
r, err := c.DoApiGet(c.GetChannelByNameForTeamNameRoute(channelName, teamName)+"?include_deleted=true", etag)
|
||||
r, err := c.DoApiGet(c.GetChannelByNameForTeamNameRoute(channelName, teamName)+"?include_deleted="+c.boolString(true), etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
@ -3059,7 +3256,7 @@ func (c *Client4) GetPing() (string, *Response) {
|
||||
// GetPingWithServerStatus will return ok if several basic server health checks
|
||||
// all pass successfully.
|
||||
func (c *Client4) GetPingWithServerStatus() (string, *Response) {
|
||||
r, err := c.DoApiGet(c.GetSystemRoute()+"/ping?get_server_status=true", "")
|
||||
r, err := c.DoApiGet(c.GetSystemRoute()+"/ping?get_server_status="+c.boolString(true), "")
|
||||
if r != nil && r.StatusCode == 500 {
|
||||
defer r.Body.Close()
|
||||
return STATUS_UNHEALTHY, BuildErrorResponse(r, err)
|
||||
@ -3187,6 +3384,19 @@ func (c *Client4) UpdateConfig(config *Config) (*Config, *Response) {
|
||||
return ConfigFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// MigrateConfig will migrate existing config to the new one.
|
||||
func (c *Client4) MigrateConfig(from, to string) (bool, *Response) {
|
||||
m := make(map[string]string, 2)
|
||||
m["from"] = from
|
||||
m["to"] = to
|
||||
r, err := c.DoApiPost(c.GetConfigRoute()+"/migrate", MapToJson(m))
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return true, BuildResponse(r)
|
||||
}
|
||||
|
||||
// UploadLicenseFile will add a license file to the system.
|
||||
func (c *Client4) UploadLicenseFile(data []byte) (bool, *Response) {
|
||||
body := &bytes.Buffer{}
|
||||
@ -3470,7 +3680,7 @@ func (c *Client4) GetSamlMetadata() (string, *Response) {
|
||||
return buf.String(), BuildResponse(r)
|
||||
}
|
||||
|
||||
func samlFileToMultipart(data []byte, filename string) ([]byte, *multipart.Writer, error) {
|
||||
func fileToMultipart(data []byte, filename string) ([]byte, *multipart.Writer, error) {
|
||||
body := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(body)
|
||||
|
||||
@ -3493,7 +3703,7 @@ func samlFileToMultipart(data []byte, filename string) ([]byte, *multipart.Write
|
||||
// UploadSamlIdpCertificate will upload an IDP certificate for SAML and set the config to use it.
|
||||
// The filename parameter is deprecated and ignored: the server will pick a hard-coded filename when writing to disk.
|
||||
func (c *Client4) UploadSamlIdpCertificate(data []byte, filename string) (bool, *Response) {
|
||||
body, writer, err := samlFileToMultipart(data, filename)
|
||||
body, writer, err := fileToMultipart(data, filename)
|
||||
if err != nil {
|
||||
return false, &Response{Error: NewAppError("UploadSamlIdpCertificate", "model.client.upload_saml_cert.app_error", nil, err.Error(), http.StatusBadRequest)}
|
||||
}
|
||||
@ -3505,7 +3715,7 @@ func (c *Client4) UploadSamlIdpCertificate(data []byte, filename string) (bool,
|
||||
// UploadSamlPublicCertificate will upload a public certificate for SAML and set the config to use it.
|
||||
// The filename parameter is deprecated and ignored: the server will pick a hard-coded filename when writing to disk.
|
||||
func (c *Client4) UploadSamlPublicCertificate(data []byte, filename string) (bool, *Response) {
|
||||
body, writer, err := samlFileToMultipart(data, filename)
|
||||
body, writer, err := fileToMultipart(data, filename)
|
||||
if err != nil {
|
||||
return false, &Response{Error: NewAppError("UploadSamlPublicCertificate", "model.client.upload_saml_cert.app_error", nil, err.Error(), http.StatusBadRequest)}
|
||||
}
|
||||
@ -3517,7 +3727,7 @@ func (c *Client4) UploadSamlPublicCertificate(data []byte, filename string) (boo
|
||||
// UploadSamlPrivateCertificate will upload a private key for SAML and set the config to use it.
|
||||
// The filename parameter is deprecated and ignored: the server will pick a hard-coded filename when writing to disk.
|
||||
func (c *Client4) UploadSamlPrivateCertificate(data []byte, filename string) (bool, *Response) {
|
||||
body, writer, err := samlFileToMultipart(data, filename)
|
||||
body, writer, err := fileToMultipart(data, filename)
|
||||
if err != nil {
|
||||
return false, &Response{Error: NewAppError("UploadSamlPrivateCertificate", "model.client.upload_saml_cert.app_error", nil, err.Error(), http.StatusBadRequest)}
|
||||
}
|
||||
@ -3685,7 +3895,19 @@ func (c *Client4) GetLdapGroups() ([]*Group, *Response) {
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
return GroupsFromJson(r.Body), BuildResponse(r)
|
||||
responseData := struct {
|
||||
Count int `json:"count"`
|
||||
Groups []*Group `json:"groups"`
|
||||
}{}
|
||||
if err := json.NewDecoder(r.Body).Decode(&responseData); err != nil {
|
||||
appErr := NewAppError("Api4.GetLdapGroups", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, BuildErrorResponse(r, appErr)
|
||||
}
|
||||
for i := range responseData.Groups {
|
||||
responseData.Groups[i].DisplayName = *responseData.Groups[i].Name
|
||||
}
|
||||
|
||||
return responseData.Groups, BuildResponse(r)
|
||||
}
|
||||
|
||||
// LinkLdapGroup creates or undeletes a Mattermost group and associates it to the given LDAP group DN.
|
||||
@ -3714,6 +3936,18 @@ func (c *Client4) UnlinkLdapGroup(dn string) (*Group, *Response) {
|
||||
return GroupFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// MigrateIdLdap migrates the LDAP enabled users to given attribute
|
||||
func (c *Client4) MigrateIdLdap(toAttribute string) (bool, *Response) {
|
||||
r, err := c.DoApiPost(c.GetLdapRoute()+"/migrateid", MapToJson(map[string]string{
|
||||
"toAttribute": toAttribute,
|
||||
}))
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// GetGroupsByChannel retrieves the Mattermost Groups associated with a given channel
|
||||
func (c *Client4) GetGroupsByChannel(channelId string, opts GroupSearchOpts) ([]*GroupWithSchemeAdmin, int, *Response) {
|
||||
path := fmt.Sprintf("%s/groups?q=%v&include_member_count=%v&filter_allow_reference=%v", c.GetChannelRoute(channelId), opts.Q, opts.IncludeMemberCount, opts.FilterAllowReference)
|
||||
@ -3828,6 +4062,74 @@ func (c *Client4) GetGroupsByUserId(userId string) ([]*Group, *Response) {
|
||||
return GroupsFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) MigrateAuthToLdap(fromAuthService string, matchField string, force bool) (bool, *Response) {
|
||||
r, err := c.DoApiPost(c.GetUsersRoute()+"/migrate_auth/ldap", StringInterfaceToJson(map[string]interface{}{
|
||||
"from": fromAuthService,
|
||||
"force": force,
|
||||
"match_field": matchField,
|
||||
}))
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) MigrateAuthToSaml(fromAuthService string, usersMap map[string]string, auto bool) (bool, *Response) {
|
||||
r, err := c.DoApiPost(c.GetUsersRoute()+"/migrate_auth/saml", StringInterfaceToJson(map[string]interface{}{
|
||||
"from": fromAuthService,
|
||||
"auto": auto,
|
||||
"matches": usersMap,
|
||||
}))
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// UploadLdapPublicCertificate will upload a public certificate for LDAP and set the config to use it.
|
||||
func (c *Client4) UploadLdapPublicCertificate(data []byte) (bool, *Response) {
|
||||
body, writer, err := fileToMultipart(data, LDAP_PUBIC_CERTIFICATE_NAME)
|
||||
if err != nil {
|
||||
return false, &Response{Error: NewAppError("UploadLdapPublicCertificate", "model.client.upload_ldap_cert.app_error", nil, err.Error(), http.StatusBadRequest)}
|
||||
}
|
||||
|
||||
_, resp := c.DoUploadFile(c.GetLdapRoute()+"/certificate/public", body, writer.FormDataContentType())
|
||||
return resp.Error == nil, resp
|
||||
}
|
||||
|
||||
// UploadLdapPrivateCertificate will upload a private key for LDAP and set the config to use it.
|
||||
func (c *Client4) UploadLdapPrivateCertificate(data []byte) (bool, *Response) {
|
||||
body, writer, err := fileToMultipart(data, LDAP_PRIVATE_KEY_NAME)
|
||||
if err != nil {
|
||||
return false, &Response{Error: NewAppError("UploadLdapPrivateCertificate", "model.client.upload_Ldap_cert.app_error", nil, err.Error(), http.StatusBadRequest)}
|
||||
}
|
||||
|
||||
_, resp := c.DoUploadFile(c.GetLdapRoute()+"/certificate/private", body, writer.FormDataContentType())
|
||||
return resp.Error == nil, resp
|
||||
}
|
||||
|
||||
// DeleteLdapPublicCertificate deletes the LDAP IDP certificate from the server and updates the config to not use it and disable LDAP.
|
||||
func (c *Client4) DeleteLdapPublicCertificate() (bool, *Response) {
|
||||
r, err := c.DoApiDelete(c.GetLdapRoute() + "/certificate/public")
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// DeleteLDAPPrivateCertificate deletes the LDAP IDP certificate from the server and updates the config to not use it and disable LDAP.
|
||||
func (c *Client4) DeleteLdapPrivateCertificate() (bool, *Response) {
|
||||
r, err := c.DoApiDelete(c.GetLdapRoute() + "/certificate/private")
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// Audits Section
|
||||
|
||||
// GetAudits returns a list of audits for the whole system.
|
||||
@ -4519,6 +4821,21 @@ func (c *Client4) CancelJob(jobId string) (bool, *Response) {
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// DownloadJob downloads the results of the job
|
||||
func (c *Client4) DownloadJob(jobId string) ([]byte, *Response) {
|
||||
r, appErr := c.DoApiGet(c.GetJobsRoute()+fmt.Sprintf("/%v/download", jobId), "")
|
||||
if appErr != nil {
|
||||
return nil, BuildErrorResponse(r, appErr)
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
data, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, NewAppError("GetFile", "model.client.read_job_result_file.app_error", nil, err.Error(), r.StatusCode))
|
||||
}
|
||||
return data, BuildResponse(r)
|
||||
}
|
||||
|
||||
// Roles Section
|
||||
|
||||
// GetRole gets a single role by ID.
|
||||
@ -4650,7 +4967,7 @@ func (c *Client4) uploadPlugin(file io.Reader, force bool) (*Manifest, *Response
|
||||
writer := multipart.NewWriter(body)
|
||||
|
||||
if force {
|
||||
err := writer.WriteField("force", "true")
|
||||
err := writer.WriteField("force", c.boolString(true))
|
||||
if err != nil {
|
||||
return nil, &Response{Error: NewAppError("UploadPlugin", "model.client.writer.app_error", nil, err.Error(), 0)}
|
||||
}
|
||||
@ -4693,10 +5010,7 @@ func (c *Client4) uploadPlugin(file io.Reader, force bool) (*Manifest, *Response
|
||||
}
|
||||
|
||||
func (c *Client4) InstallPluginFromUrl(downloadUrl string, force bool) (*Manifest, *Response) {
|
||||
forceStr := "false"
|
||||
if force {
|
||||
forceStr = "true"
|
||||
}
|
||||
forceStr := c.boolString(force)
|
||||
|
||||
url := fmt.Sprintf("%s?plugin_download_url=%s&force=%s", c.GetPluginsRoute()+"/install_from_url", url.QueryEscape(downloadUrl), forceStr)
|
||||
r, err := c.DoApiPost(url, "")
|
||||
@ -5074,6 +5388,16 @@ func (c *Client4) GetKnownUsers() ([]string, *Response) {
|
||||
return userIds, BuildResponse(r)
|
||||
}
|
||||
|
||||
// PublishUserTyping publishes a user is typing websocket event based on the provided TypingRequest.
|
||||
func (c *Client4) PublishUserTyping(userID string, typingRequest TypingRequest) (bool, *Response) {
|
||||
r, err := c.DoApiPost(c.GetPublishUserTypingRoute(userID), typingRequest.ToJson())
|
||||
if err != nil {
|
||||
return false, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) GetChannelMemberCountsByGroup(channelID string, includeTimezones bool, etag string) ([]*ChannelMemberCountByGroup, *Response) {
|
||||
r, err := c.DoApiGet(c.GetChannelRoute(channelID)+"/member_counts_by_group?include_timezones="+strconv.FormatBool(includeTimezones), etag)
|
||||
if err != nil {
|
||||
@ -5093,3 +5417,202 @@ func (c *Client4) RequestTrialLicense(users int) (bool, *Response) {
|
||||
defer closeBody(r)
|
||||
return CheckStatusOK(r), BuildResponse(r)
|
||||
}
|
||||
|
||||
// GetGroupStats retrieves stats for a Mattermost Group
|
||||
func (c *Client4) GetGroupStats(groupID string) (*GroupStats, *Response) {
|
||||
r, appErr := c.DoApiGet(c.GetGroupRoute(groupID)+"/stats", "")
|
||||
if appErr != nil {
|
||||
return nil, BuildErrorResponse(r, appErr)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return GroupStatsFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) GetSidebarCategoriesForTeamForUser(userID, teamID, etag string) (*OrderedSidebarCategories, *Response) {
|
||||
route := c.GetUserCategoryRoute(userID, teamID)
|
||||
r, appErr := c.DoApiGet(route, etag)
|
||||
if appErr != nil {
|
||||
return nil, BuildErrorResponse(r, appErr)
|
||||
}
|
||||
cat, err := OrderedSidebarCategoriesFromJson(r.Body)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, NewAppError("Client4.GetSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode))
|
||||
}
|
||||
return cat, BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) CreateSidebarCategoryForTeamForUser(userID, teamID string, category *SidebarCategoryWithChannels) (*SidebarCategoryWithChannels, *Response) {
|
||||
payload, _ := json.Marshal(category)
|
||||
route := c.GetUserCategoryRoute(userID, teamID)
|
||||
r, appErr := c.doApiPostBytes(route, payload)
|
||||
if appErr != nil {
|
||||
return nil, BuildErrorResponse(r, appErr)
|
||||
}
|
||||
defer closeBody(r)
|
||||
cat, err := SidebarCategoryFromJson(r.Body)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, NewAppError("Client4.CreateSidebarCategoryForTeamForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode))
|
||||
}
|
||||
return cat, BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) UpdateSidebarCategoriesForTeamForUser(userID, teamID string, categories []*SidebarCategoryWithChannels) ([]*SidebarCategoryWithChannels, *Response) {
|
||||
payload, _ := json.Marshal(categories)
|
||||
route := c.GetUserCategoryRoute(userID, teamID)
|
||||
|
||||
r, appErr := c.doApiPutBytes(route, payload)
|
||||
if appErr != nil {
|
||||
return nil, BuildErrorResponse(r, appErr)
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
categories, err := SidebarCategoriesFromJson(r.Body)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, NewAppError("Client4.UpdateSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode))
|
||||
}
|
||||
|
||||
return categories, BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) GetSidebarCategoryOrderForTeamForUser(userID, teamID, etag string) ([]string, *Response) {
|
||||
route := c.GetUserCategoryRoute(userID, teamID) + "/order"
|
||||
r, err := c.DoApiGet(route, etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return ArrayFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) UpdateSidebarCategoryOrderForTeamForUser(userID, teamID string, order []string) ([]string, *Response) {
|
||||
payload, _ := json.Marshal(order)
|
||||
route := c.GetUserCategoryRoute(userID, teamID) + "/order"
|
||||
r, err := c.doApiPutBytes(route, payload)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return ArrayFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) GetSidebarCategoryForTeamForUser(userID, teamID, categoryID, etag string) (*SidebarCategoryWithChannels, *Response) {
|
||||
route := c.GetUserCategoryRoute(userID, teamID) + "/" + categoryID
|
||||
r, appErr := c.DoApiGet(route, etag)
|
||||
if appErr != nil {
|
||||
return nil, BuildErrorResponse(r, appErr)
|
||||
}
|
||||
defer closeBody(r)
|
||||
cat, err := SidebarCategoryFromJson(r.Body)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, NewAppError("Client4.UpdateSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode))
|
||||
}
|
||||
|
||||
return cat, BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) UpdateSidebarCategoryForTeamForUser(userID, teamID, categoryID string, category *SidebarCategoryWithChannels) (*SidebarCategoryWithChannels, *Response) {
|
||||
payload, _ := json.Marshal(category)
|
||||
route := c.GetUserCategoryRoute(userID, teamID) + "/" + categoryID
|
||||
r, appErr := c.doApiPutBytes(route, payload)
|
||||
if appErr != nil {
|
||||
return nil, BuildErrorResponse(r, appErr)
|
||||
}
|
||||
defer closeBody(r)
|
||||
cat, err := SidebarCategoryFromJson(r.Body)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, NewAppError("Client4.UpdateSidebarCategoriesForTeamForUser", "model.utils.decode_json.app_error", nil, err.Error(), r.StatusCode))
|
||||
}
|
||||
|
||||
return cat, BuildResponse(r)
|
||||
}
|
||||
|
||||
// CheckIntegrity performs a database integrity check.
|
||||
func (c *Client4) CheckIntegrity() ([]IntegrityCheckResult, *Response) {
|
||||
r, err := c.DoApiPost("/integrity", "")
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
var results []IntegrityCheckResult
|
||||
if err := json.NewDecoder(r.Body).Decode(&results); err != nil {
|
||||
appErr := NewAppError("Api4.CheckIntegrity", "api.marshal_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
return nil, BuildErrorResponse(r, appErr)
|
||||
}
|
||||
return results, BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) GetNotices(lastViewed int64, teamId string, client NoticeClientType, clientVersion, locale, etag string) (NoticeMessages, *Response) {
|
||||
url := fmt.Sprintf("/system/notices/%s?lastViewed=%d&client=%s&clientVersion=%s&locale=%s", teamId, lastViewed, client, clientVersion, locale)
|
||||
r, appErr := c.DoApiGet(url, etag)
|
||||
if appErr != nil {
|
||||
return nil, BuildErrorResponse(r, appErr)
|
||||
}
|
||||
defer closeBody(r)
|
||||
notices, err := UnmarshalProductNoticeMessages(r.Body)
|
||||
if err != nil {
|
||||
return nil, &Response{StatusCode: http.StatusBadRequest, Error: NewAppError(url, "model.client.connecting.app_error", nil, err.Error(), http.StatusForbidden)}
|
||||
}
|
||||
return notices, BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) MarkNoticesViewed(ids []string) *Response {
|
||||
r, err := c.DoApiPut("/system/notices/view", ArrayToJson(ids))
|
||||
if err != nil {
|
||||
return BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return BuildResponse(r)
|
||||
}
|
||||
|
||||
// CreateUpload creates a new upload session.
|
||||
func (c *Client4) CreateUpload(us *UploadSession) (*UploadSession, *Response) {
|
||||
r, err := c.DoApiPost(c.GetUploadsRoute(), us.ToJson())
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return UploadSessionFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// GetUpload returns the upload session for the specified uploadId.
|
||||
func (c *Client4) GetUpload(uploadId string) (*UploadSession, *Response) {
|
||||
r, err := c.DoApiGet(c.GetUploadRoute(uploadId), "")
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return UploadSessionFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// GetUploadsForUser returns the upload sessions created by the specified
|
||||
// userId.
|
||||
func (c *Client4) GetUploadsForUser(userId string) ([]*UploadSession, *Response) {
|
||||
r, err := c.DoApiGet(c.GetUserRoute(userId)+"/uploads", "")
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return UploadSessionsFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
// UploadData performs an upload. On success it returns
|
||||
// a FileInfo object.
|
||||
func (c *Client4) UploadData(uploadId string, data io.Reader) (*FileInfo, *Response) {
|
||||
url := c.GetUploadRoute(uploadId)
|
||||
r, err := c.doApiRequestReader("POST", c.ApiUrl+url, data, "")
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return FileInfoFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client4) UpdatePassword(userId, currentPassword, newPassword string) *Response {
|
||||
requestBody := map[string]string{"current_password": currentPassword, "new_password": newPassword}
|
||||
r, err := c.DoApiPut(c.GetUserRoute(userId)+"/password", MapToJson(requestBody))
|
||||
if err != nil {
|
||||
return BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
return BuildResponse(r)
|
||||
}
|
||||
|
Reference in New Issue
Block a user