Skip to content

Commit

Permalink
renamed function to G(g)etPublicChannelsForTeam
Browse files Browse the repository at this point in the history
  • Loading branch information
saturninoabril committed Mar 9, 2017
1 parent 2acc99d commit 65551ff
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 35 deletions.
6 changes: 3 additions & 3 deletions api4/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func InitChannel() {
BaseRoutes.Channels.Handle("", ApiSessionRequired(createChannel)).Methods("POST")
BaseRoutes.Channels.Handle("/direct", ApiSessionRequired(createDirectChannel)).Methods("POST")

BaseRoutes.Team.Handle("/channels", ApiSessionRequired(getPublicChannels)).Methods("GET")
BaseRoutes.Team.Handle("/channels", ApiSessionRequired(getPublicChannelsForTeam)).Methods("GET")

BaseRoutes.Channel.Handle("", ApiSessionRequired(getChannel)).Methods("GET")
BaseRoutes.ChannelByName.Handle("", ApiSessionRequired(getChannelByName)).Methods("GET")
Expand Down Expand Up @@ -117,7 +117,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
}

func getPublicChannels(c *Context, w http.ResponseWriter, r *http.Request) {
func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequireTeamId()
if c.Err != nil {
return
Expand All @@ -128,7 +128,7 @@ func getPublicChannels(c *Context, w http.ResponseWriter, r *http.Request) {
return
}

if channels, err := app.GetPublicChannels(c.Params.TeamId, c.Params.Page, c.Params.PerPage); err != nil {
if channels, err := app.GetPublicChannelsForTeam(c.Params.TeamId, c.Params.Page, c.Params.PerPage); err != nil {
c.Err = err
return
} else {
Expand Down
22 changes: 11 additions & 11 deletions api4/channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ func TestGetChannel(t *testing.T) {
CheckNotFoundStatus(t, resp)
}

func TestGetPublicChannels(t *testing.T) {
func TestGetPublicChannelsForTeam(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()
Client := th.Client
team := th.BasicTeam
publicChannel1 := th.BasicChannel
publicChannel2 := th.BasicChannel2

channels, resp := Client.GetPublicChannels(team.Id, 0, 100, "")
channels, resp := Client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
CheckNoError(t, resp)
if len(*channels) != 4 {
t.Fatal("wrong length")
Expand All @@ -281,7 +281,7 @@ func TestGetPublicChannels(t *testing.T) {
}

privateChannel := th.CreatePrivateChannel()
channels, resp = Client.GetPublicChannels(team.Id, 0, 100, "")
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
CheckNoError(t, resp)
if len(*channels) != 4 {
t.Fatal("wrong length")
Expand All @@ -297,40 +297,40 @@ func TestGetPublicChannels(t *testing.T) {
}
}

channels, resp = Client.GetPublicChannels(team.Id, 0, 1, "")
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 1, "")
CheckNoError(t, resp)
if len(*channels) != 1 {
t.Fatal("should be one channel per page")
}

channels, resp = Client.GetPublicChannels(team.Id, 1, 1, "")
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 1, 1, "")
CheckNoError(t, resp)
if len(*channels) != 1 {
t.Fatal("should be one channel per page")
}

channels, resp = Client.GetPublicChannels(team.Id, 10000, 100, "")
channels, resp = Client.GetPublicChannelsForTeam(team.Id, 10000, 100, "")
CheckNoError(t, resp)
if len(*channels) != 0 {
t.Fatal("should be no channel")
}

_, resp = Client.GetPublicChannels("junk", 0, 100, "")
_, resp = Client.GetPublicChannelsForTeam("junk", 0, 100, "")
CheckBadRequestStatus(t, resp)

_, resp = Client.GetPublicChannels(model.NewId(), 0, 100, "")
_, resp = Client.GetPublicChannelsForTeam(model.NewId(), 0, 100, "")
CheckForbiddenStatus(t, resp)

Client.Logout()
_, resp = Client.GetPublicChannels(team.Id, 0, 100, "")
_, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
CheckUnauthorizedStatus(t, resp)

user := th.CreateUser()
Client.Login(user.Email, user.Password)
_, resp = Client.GetPublicChannels(team.Id, 0, 100, "")
_, resp = Client.GetPublicChannelsForTeam(team.Id, 0, 100, "")
CheckForbiddenStatus(t, resp)

_, resp = th.SystemAdminClient.GetPublicChannels(team.Id, 0, 100, "")
_, resp = th.SystemAdminClient.GetPublicChannelsForTeam(team.Id, 0, 100, "")
CheckNoError(t, resp)
}

Expand Down
4 changes: 2 additions & 2 deletions app/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,8 @@ func GetChannelsUserNotIn(teamId string, userId string, offset int, limit int) (
}
}

func GetPublicChannels(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
if result := <-Srv.Store.Channel().GetPublicChannels(teamId, offset, limit); result.Err != nil {
func GetPublicChannelsForTeam(teamId string, offset int, limit int) (*model.ChannelList, *model.AppError) {
if result := <-Srv.Store.Channel().GetPublicChannelsForTeam(teamId, offset, limit); result.Err != nil {
return nil, result.Err
} else {
return result.Data.(*model.ChannelList), nil
Expand Down
8 changes: 4 additions & 4 deletions model/client4.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (c *Client4) GetChannelsRoute() string {
return fmt.Sprintf("/channels")
}

func (c *Client4) GetPublicChannelsRoute(teamId string) string {
func (c *Client4) GetPublicChannelsForTeamRoute(teamId string) string {
return fmt.Sprintf(c.GetTeamRoute(teamId) + "/channels")
}

Expand Down Expand Up @@ -702,10 +702,10 @@ func (c *Client4) GetChannel(channelId, etag string) (*Channel, *Response) {
}
}

// GetPublicChannels returns a channel based on the provided team id string.
func (c *Client4) GetPublicChannels(teamId string, page int, perPage int, etag string) (*ChannelList, *Response) {
// GetPublicChannelsForTeam returns a channel based on the provided team id string.
func (c *Client4) GetPublicChannelsForTeam(teamId string, page int, perPage int, etag string) (*ChannelList, *Response) {
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
if r, err := c.DoApiGet(c.GetPublicChannelsRoute(teamId)+query, etag); err != nil {
if r, err := c.DoApiGet(c.GetPublicChannelsForTeamRoute(teamId)+query, etag); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
Expand Down
6 changes: 3 additions & 3 deletions store/sql_channel_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset in
return storeChannel
}

func (s SqlChannelStore) GetPublicChannels(teamId string, offset int, limit int) StoreChannel {
func (s SqlChannelStore) GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel {
storeChannel := make(StoreChannel, 1)

go func() {
Expand All @@ -538,15 +538,15 @@ func (s SqlChannelStore) GetPublicChannels(teamId string, offset int, limit int)
Channels
WHERE
TeamId = :TeamId
AND Type IN ('O')
AND Type = 'O'
AND DeleteAt = 0
ORDER BY DisplayName
LIMIT :Limit
OFFSET :Offset`,
map[string]interface{}{"TeamId": teamId, "Limit": limit, "Offset": offset})

if err != nil {
result.Err = model.NewLocAppError("SqlChannelStore.GetPublicChannels", "store.sql_channel.get_public_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error())
result.Err = model.NewLocAppError("SqlChannelStore.GetPublicChannelsForTeam", "store.sql_channel.get_public_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error())
} else {
result.Data = data
}
Expand Down
16 changes: 5 additions & 11 deletions store/sql_channel_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
}
}

func TestChannelStoreGetPublicChannels(t *testing.T) {
func TestChannelStoreGetPublicChannelsForTeam(t *testing.T) {
Setup()

o1 := model.Channel{}
Expand All @@ -792,20 +792,14 @@ func TestChannelStoreGetPublicChannels(t *testing.T) {
o2.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(&o2))

m3 := model.ChannelMember{}
m3.ChannelId = o2.Id
m3.UserId = model.NewId()
m3.NotifyProps = model.GetDefaultChannelNotifyProps()
Must(store.Channel().SaveMember(&m3))

o3 := model.Channel{}
o3.TeamId = o1.TeamId
o3.DisplayName = "PrivateChannel1Team1"
o3.Name = "a" + model.NewId() + "b"
o3.Type = model.CHANNEL_PRIVATE
Must(store.Channel().Save(&o3))

cresult := <-store.Channel().GetPublicChannels(o1.TeamId, 0, 100)
cresult := <-store.Channel().GetPublicChannelsForTeam(o1.TeamId, 0, 100)
if cresult.Err != nil {
t.Fatal(cresult.Err)
}
Expand All @@ -826,21 +820,21 @@ func TestChannelStoreGetPublicChannels(t *testing.T) {
o4.Type = model.CHANNEL_OPEN
Must(store.Channel().Save(&o4))

cresult = <-store.Channel().GetPublicChannels(o1.TeamId, 0, 100)
cresult = <-store.Channel().GetPublicChannelsForTeam(o1.TeamId, 0, 100)
list = cresult.Data.(*model.ChannelList)

if len(*list) != 2 {
t.Fatal("wrong list length")
}

cresult = <-store.Channel().GetPublicChannels(o1.TeamId, 0, 1)
cresult = <-store.Channel().GetPublicChannelsForTeam(o1.TeamId, 0, 1)
list = cresult.Data.(*model.ChannelList)

if len(*list) != 1 {
t.Fatal("wrong list length")
}

cresult = <-store.Channel().GetPublicChannels(o1.TeamId, 1, 1)
cresult = <-store.Channel().GetPublicChannelsForTeam(o1.TeamId, 1, 1)
list = cresult.Data.(*model.ChannelList)

if len(*list) != 1 {
Expand Down
2 changes: 1 addition & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ type ChannelStore interface {
GetDeletedByName(team_id string, name string) StoreChannel
GetChannels(teamId string, userId string) StoreChannel
GetMoreChannels(teamId string, userId string, offset int, limit int) StoreChannel
GetPublicChannels(teamId string, offset int, limit int) StoreChannel
GetPublicChannelsForTeam(teamId string, offset int, limit int) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel
GetTeamChannels(teamId string) StoreChannel
GetAll(teamId string) StoreChannel
Expand Down

0 comments on commit 65551ff

Please sign in to comment.