summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorMartin Kraft <mkraft@users.noreply.github.com>2018-05-02 07:31:14 -0400
committerGitHub <noreply@github.com>2018-05-02 07:31:14 -0400
commitf4dcb4edf2aafca85c9af631131a77888da24bc7 (patch)
tree83d507f4a06d84227ffa9dc8d28b098908853305 /app
parentd2cc0c5834d6849f2fdb1e343ed5e193b742fa2f (diff)
downloadchat-f4dcb4edf2aafca85c9af631131a77888da24bc7.tar.gz
chat-f4dcb4edf2aafca85c9af631131a77888da24bc7.tar.bz2
chat-f4dcb4edf2aafca85c9af631131a77888da24bc7.zip
MM-10182 & MM-10183: Adds channel scheme and team scheme API endpoint. (#8680)
* MM-10183: Adds channel scheme API endpoint. MM-10182: Adds team scheme API endpoint. MM-10182_3: Switch from scheme_id in path to body. * MM-10182/MM-10183: Changes path from 'schemes' to 'scheme'. * MM-10182: Fix merge error.
Diffstat (limited to 'app')
-rw-r--r--app/channel.go17
-rw-r--r--app/channel_test.go18
-rw-r--r--app/team.go18
-rw-r--r--app/team_test.go18
4 files changed, 71 insertions, 0 deletions
diff --git a/app/channel.go b/app/channel.go
index 516e8d094..4b606ac27 100644
--- a/app/channel.go
+++ b/app/channel.go
@@ -354,6 +354,23 @@ func (a *App) UpdateChannel(channel *model.Channel) (*model.Channel, *model.AppE
}
}
+func (a *App) UpdateChannelScheme(channel *model.Channel) (*model.Channel, *model.AppError) {
+ var oldChannel *model.Channel
+ var err *model.AppError
+ if oldChannel, err = a.GetChannel(channel.Id); err != nil {
+ return nil, err
+ }
+
+ oldChannel.SchemeId = channel.SchemeId
+
+ newChannel, err := a.UpdateChannel(oldChannel)
+ if err != nil {
+ return nil, err
+ }
+
+ return newChannel, nil
+}
+
func (a *App) UpdateChannelPrivacy(oldChannel *model.Channel, user *model.User) (*model.Channel, *model.AppError) {
if channel, err := a.UpdateChannel(oldChannel); err != nil {
return channel, err
diff --git a/app/channel_test.go b/app/channel_test.go
index de8a6a6a0..336d9b25b 100644
--- a/app/channel_test.go
+++ b/app/channel_test.go
@@ -381,3 +381,21 @@ func TestAddChannelMemberNoUserRequestor(t *testing.T) {
assert.Equal(t, user.Username, post.Props["username"])
}
}
+
+func TestAppUpdateChannelScheme(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ channel := th.BasicChannel
+ mockID := model.NewString("x")
+ channel.SchemeId = mockID
+
+ updatedChannel, err := th.App.UpdateChannelScheme(channel)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if updatedChannel.SchemeId != mockID {
+ t.Fatal("Wrong Channel SchemeId")
+ }
+}
diff --git a/app/team.go b/app/team.go
index 4fc410934..d8ebbab2a 100644
--- a/app/team.go
+++ b/app/team.go
@@ -114,6 +114,24 @@ func (a *App) UpdateTeam(team *model.Team) (*model.Team, *model.AppError) {
return oldTeam, nil
}
+func (a *App) UpdateTeamScheme(team *model.Team) (*model.Team, *model.AppError) {
+ var oldTeam *model.Team
+ var err *model.AppError
+ if oldTeam, err = a.GetTeam(team.Id); err != nil {
+ return nil, err
+ }
+
+ oldTeam.SchemeId = team.SchemeId
+
+ if result := <-a.Srv.Store.Team().Update(oldTeam); result.Err != nil {
+ return nil, result.Err
+ }
+
+ a.sendTeamEvent(oldTeam, model.WEBSOCKET_EVENT_UPDATE_TEAM)
+
+ return oldTeam, nil
+}
+
func (a *App) PatchTeam(teamId string, patch *model.TeamPatch) (*model.Team, *model.AppError) {
team, err := a.GetTeam(teamId)
if err != nil {
diff --git a/app/team_test.go b/app/team_test.go
index 7ebfb8166..6a47da58b 100644
--- a/app/team_test.go
+++ b/app/team_test.go
@@ -559,3 +559,21 @@ func TestJoinUserToTeam(t *testing.T) {
}
})
}
+
+func TestAppUpdateTeamScheme(t *testing.T) {
+ th := Setup().InitBasic()
+ defer th.TearDown()
+
+ team := th.BasicTeam
+ mockID := model.NewString("x")
+ team.SchemeId = mockID
+
+ updatedTeam, err := th.App.UpdateTeamScheme(th.BasicTeam)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if updatedTeam.SchemeId != mockID {
+ t.Fatal("Wrong Team SchemeId")
+ }
+}