diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/channel.go | 5 | ||||
-rw-r--r-- | model/client4.go | 42 | ||||
-rw-r--r-- | model/team.go | 3 | ||||
-rw-r--r-- | model/user.go | 4 | ||||
-rw-r--r-- | model/utils.go | 2 |
5 files changed, 49 insertions, 7 deletions
diff --git a/model/channel.go b/model/channel.go index 2ad257ccc..3ad7da1fa 100644 --- a/model/channel.go +++ b/model/channel.go @@ -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) } diff --git a/model/client4.go b/model/client4.go index 7afc63359..5c51026a9 100644 --- a/model/client4.go +++ b/model/client4.go @@ -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) diff --git a/model/team.go b/model/team.go index 310ad2d91..99444bc5e 100644 --- a/model/team.go +++ b/model/team.go @@ -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 } diff --git a/model/user.go b/model/user.go index b2b077e5f..8e02fe1ab 100644 --- a/model/user.go +++ b/model/user.go @@ -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 } diff --git a/model/utils.go b/model/utils.go index 9ecc19595..fcdf5b5cd 100644 --- a/model/utils.go +++ b/model/utils.go @@ -280,7 +280,7 @@ func IsValidChannelIdentifier(s string) bool { return false } - if len(s) < 2 { + if len(s) < CHANNEL_NAME_MIN_LENGTH { return false } |