Implement GET channels endpoints for APIv4 (#5363)

* implement get channels endpoints and updated drivers and unittests

* removed channel deletion on tear down, removed manage permission on get channels endpoints, and updated utils to add constant channel length

* added constants for user, team and channel length, updated context to use the model functions

* make sure team name length should be less than the minimum length and revert underscore to team name validity

* changed post test condition from notfound to unauthorized
Этот коммит содержится в:
Ruzette Tanyag
2017-02-14 10:28:08 -05:00
коммит произвёл Harrison Healey
родитель 9dabd10da9
Коммит 28aa7cdbf2
14 изменённых файлов: 293 добавлений и 42 удалений

Просмотреть файл

@@ -15,6 +15,7 @@ const (
CHANNEL_DIRECT = "D"
DEFAULT_CHANNEL = "town-square"
CHANNEL_DISPLAY_NAME_MAX_RUNES = 64
CHANNEL_NAME_MIN_LENGTH = 3
CHANNEL_NAME_MAX_LENGTH = 64
CHANNEL_HEADER_MAX_RUNES = 1024
CHANNEL_PURPOSE_MAX_RUNES = 250
@@ -83,10 +84,6 @@ func (o *Channel) IsValid() *AppError {
return NewLocAppError("Channel.IsValid", "model.channel.is_valid.display_name.app_error", nil, "id="+o.Id)
}
if len(o.Name) > CHANNEL_NAME_MAX_LENGTH {
return NewLocAppError("Channel.IsValid", "model.channel.is_valid.name.app_error", nil, "id="+o.Id)
}
if !IsValidChannelIdentifier(o.Name) {
return NewLocAppError("Channel.IsValid", "model.channel.is_valid.2_or_more.app_error", nil, "id="+o.Id)
}

Просмотреть файл

@@ -72,6 +72,10 @@ func (c *Client4) GetTeamRoute(teamId string) string {
return fmt.Sprintf(c.GetTeamsRoute()+"/%v", teamId)
}
func (c *Client4) GetTeamByNameRoute(teamName string) string {
return fmt.Sprintf(c.GetTeamsRoute()+"/name/%v", teamName)
}
func (c *Client4) GetTeamMemberRoute(teamId, userId string) string {
return fmt.Sprintf(c.GetTeamRoute(teamId)+"/members/%v", userId)
}
@@ -84,6 +88,14 @@ func (c *Client4) GetChannelRoute(channelId string) string {
return fmt.Sprintf(c.GetChannelsRoute()+"/%v", channelId)
}
func (c *Client4) GetChannelByNameRoute(channelName, teamId string) string {
return fmt.Sprintf(c.GetTeamRoute(teamId)+"/channels/name/%v", channelName)
}
func (c *Client4) GetChannelByNameForTeamNameRoute(channelName, teamName string) string {
return fmt.Sprintf(c.GetTeamByNameRoute(teamName)+"/channels/name/%v", channelName)
}
func (c *Client4) GetChannelMembersRoute(channelId string) string {
return fmt.Sprintf(c.GetChannelRoute(channelId) + "/members")
}
@@ -444,6 +456,36 @@ func (c *Client4) CreateDirectChannel(userId1, userId2 string) (*Channel, *Respo
}
}
// GetChannel returns a channel based on the provided channel id string.
func (c *Client4) GetChannel(channelId, etag string) (*User, *Response) {
if r, err := c.DoApiGet(c.GetChannelRoute(channelId), etag); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return UserFromJson(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) (*User, *Response) {
if r, err := c.DoApiGet(c.GetChannelByNameRoute(channelName, teamId), etag); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return UserFromJson(r.Body), BuildResponse(r)
}
}
// GetChannelByNameForTeamName returns a channel based on the provided channel name and team name strings.
func (c *Client4) GetChannelByNameForTeamName(channelName, teamName string, etag string) (*User, *Response) {
if r, err := c.DoApiGet(c.GetChannelByNameForTeamNameRoute(channelName, teamName), etag); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return UserFromJson(r.Body), BuildResponse(r)
}
}
// GetChannelMembers gets a page of channel members.
func (c *Client4) GetChannelMembers(channelId string, page, perPage int, etag string) (*ChannelMembers, *Response) {
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)

Просмотреть файл

@@ -22,6 +22,7 @@ const (
TEAM_DISPLAY_NAME_MAX_RUNES = 64
TEAM_EMAIL_MAX_LENGTH = 128
TEAM_NAME_MAX_LENGTH = 64
TEAM_NAME_MIN_LENGTH = 2
)
type Team struct {
@@ -228,7 +229,7 @@ func IsValidTeamName(s string) bool {
return false
}
if len(s) <= 1 {
if len(s) < TEAM_NAME_MIN_LENGTH {
return false
}

Просмотреть файл

@@ -29,6 +29,8 @@ const (
USER_FIRST_NAME_MAX_RUNES = 64
USER_LAST_NAME_MAX_RUNES = 64
USER_AUTH_DATA_MAX_LENGTH = 128
USER_NAME_MAX_LENGTH = 64
USER_NAME_MIN_LENGTH = 3
)
type User struct {
@@ -487,7 +489,7 @@ var restrictedUsernames = []string{
}
func IsValidUsername(s string) bool {
if len(s) == 0 || len(s) > 64 {
if len(s) < USER_NAME_MIN_LENGTH || len(s) > USER_NAME_MAX_LENGTH {
return false
}

Просмотреть файл

@@ -280,7 +280,7 @@ func IsValidChannelIdentifier(s string) bool {
return false
}
if len(s) < 2 {
if len(s) < CHANNEL_NAME_MIN_LENGTH {
return false
}