Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
mattermost-server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
sysadmin
mattermost
mattermost-server
Commits
1adfd0e9
Commit
1adfd0e9
authored
Sep 06, 2017
by
Chris
Committed by
GitHub
Sep 06, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
app type transition (#7167)
parent
b84bd210
Changes
178
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
178 changed files
with
2919 additions
and
2806 deletions
+2919
-2806
api/admin.go
api/admin.go
+10
-10
api/admin_test.go
api/admin_test.go
+2
-3
api/api.go
api/api.go
+5
-5
api/apitestlib.go
api/apitestlib.go
+25
-21
api/channel.go
api/channel.go
+60
-60
api/channel_test.go
api/channel_test.go
+11
-12
api/cli_test.go
api/cli_test.go
+3
-3
api/command.go
api/command.go
+11
-11
api/command_help_test.go
api/command_help_test.go
+2
-1
api/command_msg_test.go
api/command_msg_test.go
+2
-1
api/context.go
api/context.go
+10
-8
api/emoji.go
api/emoji.go
+8
-7
api/emoji_test.go
api/emoji_test.go
+5
-5
api/file.go
api/file.go
+5
-5
api/file_test.go
api/file_test.go
+25
-25
api/license.go
api/license.go
+2
-2
api/license_test.go
api/license_test.go
+2
-1
api/oauth.go
api/oauth.go
+15
-15
api/oauth_test.go
api/oauth_test.go
+7
-8
api/post.go
api/post.go
+31
-31
api/post_test.go
api/post_test.go
+20
-20
api/preference.go
api/preference.go
+7
-7
api/preference_test.go
api/preference_test.go
+2
-1
api/reaction.go
api/reaction.go
+9
-9
api/status.go
api/status.go
+1
-1
api/status_test.go
api/status_test.go
+5
-6
api/team.go
api/team.go
+23
-23
api/team_test.go
api/team_test.go
+13
-14
api/user.go
api/user.go
+55
-55
api/user_test.go
api/user_test.go
+41
-41
api/webhook.go
api/webhook.go
+18
-18
api/websocket.go
api/websocket.go
+1
-1
api4/api.go
api4/api.go
+5
-5
api4/apitestlib.go
api4/apitestlib.go
+39
-35
api4/channel.go
api4/channel.go
+54
-54
api4/channel_test.go
api4/channel_test.go
+34
-35
api4/command.go
api4/command.go
+14
-14
api4/command_help_test.go
api4/command_help_test.go
+2
-1
api4/command_test.go
api4/command_test.go
+8
-9
api4/compliance.go
api4/compliance.go
+4
-4
api4/context.go
api4/context.go
+6
-4
api4/emoji.go
api4/emoji.go
+6
-6
api4/file.go
api4/file.go
+13
-13
api4/file_test.go
api4/file_test.go
+6
-6
api4/job.go
api4/job.go
+3
-3
api4/job_test.go
api4/job_test.go
+9
-10
api4/oauth.go
api4/oauth.go
+25
-25
api4/plugin.go
api4/plugin.go
+3
-3
api4/plugin_test.go
api4/plugin_test.go
+2
-3
api4/post.go
api4/post.go
+36
-36
api4/post_test.go
api4/post_test.go
+17
-17
api4/preference.go
api4/preference.go
+5
-5
api4/reaction.go
api4/reaction.go
+6
-6
api4/reaction_test.go
api4/reaction_test.go
+19
-20
api4/status.go
api4/status.go
+5
-5
api4/status_test.go
api4/status_test.go
+7
-8
api4/system.go
api4/system.go
+9
-9
api4/team.go
api4/team.go
+29
-29
api4/team_test.go
api4/team_test.go
+10
-11
api4/user.go
api4/user.go
+64
-64
api4/user_test.go
api4/user_test.go
+17
-18
api4/webhook.go
api4/webhook.go
+30
-30
api4/webhook_test.go
api4/webhook_test.go
+1
-2
api4/websocket.go
api4/websocket.go
+1
-1
app/admin.go
app/admin.go
+12
-11
app/analytics.go
app/analytics.go
+27
-27
app/app.go
app/app.go
+10
-0
app/apptestlib.go
app/apptestlib.go
+23
-23
app/audit.go
app/audit.go
+4
-4
app/authentication.go
app/authentication.go
+9
-9
app/authorization.go
app/authorization.go
+26
-26
app/authorization_test.go
app/authorization_test.go
+2
-1
app/auto_environment.go
app/auto_environment.go
+3
-2
app/auto_posts.go
app/auto_posts.go
+3
-2
app/auto_users.go
app/auto_users.go
+5
-5
app/channel.go
app/channel.go
+192
-192
app/channel_test.go
app/channel_test.go
+26
-24
app/cluster_discovery.go
app/cluster_discovery.go
+6
-6
app/cluster_discovery_test.go
app/cluster_discovery_test.go
+2
-1
app/cluster_handlers.go
app/cluster_handlers.go
+25
-25
app/command.go
app/command.go
+29
-29
app/command_away.go
app/command_away.go
+1
-1
app/command_channel_header.go
app/command_channel_header.go
+4
-4
app/command_channel_purpose.go
app/command_channel_purpose.go
+4
-4
app/command_channel_rename.go
app/command_channel_rename.go
+4
-4
app/command_channel_rename_test.go
app/command_channel_rename_test.go
+2
-1
app/command_echo.go
app/command_echo.go
+1
-1
app/command_expand_collapse.go
app/command_expand_collapse.go
+4
-4
app/command_invite_people.go
app/command_invite_people.go
+1
-1
app/command_join.go
app/command_join.go
+4
-4
app/command_leave.go
app/command_leave.go
+3
-3
app/command_loadtest.go
app/command_loadtest.go
+7
-7
app/command_logout.go
app/command_logout.go
+1
-1
app/command_msg.go
app/command_msg.go
+5
-5
app/command_offline.go
app/command_offline.go
+1
-1
app/command_online.go
app/command_online.go
+1
-1
app/compliance.go
app/compliance.go
+8
-7
app/diagnostics.go
app/diagnostics.go
+16
-16
app/diagnostics_test.go
app/diagnostics_test.go
+4
-3
app/email.go
app/email.go
+4
-3
app/email_batching.go
app/email_batching.go
+13
-12
app/email_batching_test.go
app/email_batching_test.go
+36
-30
app/email_test.go
app/email_test.go
+24
-14
app/emoji.go
app/emoji.go
+14
-14
app/file.go
app/file.go
+15
-15
app/file_test.go
app/file_test.go
+8
-7
app/import.go
app/import.go
+83
-83
app/import_test.go
app/import_test.go
+199
-187
app/job.go
app/job.go
+10
-10
app/job_test.go
app/job_test.go
+17
-15
app/ldap.go
app/ldap.go
+8
-8
app/license.go
app/license.go
+14
-14
app/license_test.go
app/license_test.go
+11
-7
app/login.go
app/login.go
+7
-7
app/notification.go
app/notification.go
+32
-32
app/notification_test.go
app/notification_test.go
+42
-30
app/oauth.go
app/oauth.go
+85
-85
app/oauth_test.go
app/oauth_test.go
+14
-12
app/plugins.go
app/plugins.go
+27
-27
app/post.go
app/post.go
+82
-82
app/post_test.go
app/post_test.go
+14
-11
app/preference.go
app/preference.go
+12
-11
app/reaction.go
app/reaction.go
+12
-12
app/saml.go
app/saml.go
+2
-1
app/security_update_check.go
app/security_update_check.go
+9
-9
app/server.go
app/server.go
+17
-19
app/session.go
app/session.go
+39
-39
app/session_test.go
app/session_test.go
+2
-1
app/slackimport.go
app/slackimport.go
+39
-38
app/status.go
app/status.go
+16
-16
app/team.go
app/team.go
+120
-120
app/team_test.go
app/team_test.go
+34
-28
app/user.go
app/user.go
+204
-204
app/user_test.go
app/user_test.go
+23
-17
app/web_conn.go
app/web_conn.go
+8
-8
app/web_hub.go
app/web_hub.go
+31
-31
app/webhook.go
app/webhook.go
+56
-56
app/webhook_test.go
app/webhook_test.go
+6
-5
app/websocket_router.go
app/websocket_router.go
+5
-4
cmd/platform/channel.go
cmd/platform/channel.go
+13
-13
cmd/platform/channelargs.go
cmd/platform/channelargs.go
+2
-2
cmd/platform/config.go
cmd/platform/config.go
+2
-1
cmd/platform/import.go
cmd/platform/import.go
+3
-2
cmd/platform/init.go
cmd/platform/init.go
+3
-3
cmd/platform/license.go
cmd/platform/license.go
+1
-1
cmd/platform/mattermost.go
cmd/platform/mattermost.go
+1
-1
cmd/platform/roles.go
cmd/platform/roles.go
+2
-2
cmd/platform/server.go
cmd/platform/server.go
+15
-15
cmd/platform/team.go
cmd/platform/team.go
+4
-4
cmd/platform/teamargs.go
cmd/platform/teamargs.go
+2
-2
cmd/platform/test.go
cmd/platform/test.go
+7
-6
cmd/platform/user.go
cmd/platform/user.go
+7
-7
cmd/platform/userargs.go
cmd/platform/userargs.go
+3
-3
cmd/platform/version.go
cmd/platform/version.go
+1
-1
jobs/jobs.go
jobs/jobs.go
+2
-1
manualtesting/manual_testing.go
manualtesting/manual_testing.go
+6
-6
manualtesting/test_autolink.go
manualtesting/test_autolink.go
+2
-1
model/gitlab/gitlab.go
model/gitlab/gitlab.go
+3
-2
model/manifest_test.go
model/manifest_test.go
+2
-1
model/websocket_client.go
model/websocket_client.go
+1
-0
store/sql_command_store_test.go
store/sql_command_store_test.go
+2
-1
store/sql_compliance_store_test.go
store/sql_compliance_store_test.go
+2
-1
store/sql_emoji_store_test.go
store/sql_emoji_store_test.go
+2
-1
store/sql_job_store_test.go
store/sql_job_store_test.go
+4
-3
store/sql_license_store_test.go
store/sql_license_store_test.go
+2
-1
store/sql_oauth_store_test.go
store/sql_oauth_store_test.go
+2
-1
store/sql_session_store_test.go
store/sql_session_store_test.go
+2
-1
utils/license_test.go
utils/license_test.go
+2
-1
utils/logger/logger.go
utils/logger/logger.go
+2
-1
utils/mail.go
utils/mail.go
+2
-1
web/web.go
web/web.go
+1
-1
web/web_test.go
web/web_test.go
+10
-10
wsapi/api.go
wsapi/api.go
+1
-1
wsapi/status.go
wsapi/status.go
+3
-3
wsapi/system.go
wsapi/system.go
+1
-1
wsapi/user.go
wsapi/user.go
+1
-1
wsapi/webrtc.go
wsapi/webrtc.go
+1
-1
wsapi/websocket_handler.go
wsapi/websocket_handler.go
+3
-2
No files found.
api/admin.go
View file @
1adfd0e9
...
...
@@ -67,7 +67,7 @@ func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) {
}
func
getAllAudits
(
c
*
Context
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
audits
,
err
:=
a
pp
.
GetAudits
(
""
,
200
);
err
!=
nil
{
if
audits
,
err
:=
c
.
A
pp
.
GetAudits
(
""
,
200
);
err
!=
nil
{
c
.
Err
=
err
return
}
else
if
HandleEtag
(
audits
.
Etag
(),
"Get All Audits"
,
w
,
r
)
{
...
...
@@ -96,7 +96,7 @@ func reloadConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
func
invalidateAllCaches
(
c
*
Context
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
err
:=
a
pp
.
InvalidateAllCaches
()
err
:=
c
.
A
pp
.
InvalidateAllCaches
()
if
err
!=
nil
{
c
.
Err
=
err
return
...
...
@@ -124,7 +124,7 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
}
func
recycleDatabaseConnection
(
c
*
Context
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
a
pp
.
RecycleDatabaseConnection
()
c
.
A
pp
.
RecycleDatabaseConnection
()
w
.
Header
()
.
Set
(
"Cache-Control"
,
"no-cache, no-store, must-revalidate"
)
ReturnStatusOK
(
w
)
}
...
...
@@ -136,7 +136,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
err
:=
a
pp
.
TestEmail
(
c
.
Session
.
UserId
,
cfg
)
err
:=
c
.
A
pp
.
TestEmail
(
c
.
Session
.
UserId
,
cfg
)
if
err
!=
nil
{
c
.
Err
=
err
return
...
...
@@ -148,7 +148,7 @@ func testEmail(c *Context, w http.ResponseWriter, r *http.Request) {
}
func
getComplianceReports
(
c
*
Context
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
crs
,
err
:=
a
pp
.
GetComplianceReports
(
0
,
10000
)
crs
,
err
:=
c
.
A
pp
.
GetComplianceReports
(
0
,
10000
)
if
err
!=
nil
{
c
.
Err
=
err
return
...
...
@@ -165,7 +165,7 @@ func saveComplianceReport(c *Context, w http.ResponseWriter, r *http.Request) {
job
.
UserId
=
c
.
Session
.
UserId
rjob
,
err
:=
a
pp
.
SaveComplianceReport
(
job
)
rjob
,
err
:=
c
.
A
pp
.
SaveComplianceReport
(
job
)
if
err
!=
nil
{
c
.
Err
=
err
return
...
...
@@ -184,7 +184,7 @@ func downloadComplianceReport(c *Context, w http.ResponseWriter, r *http.Request
return
}
job
,
err
:=
a
pp
.
GetComplianceReport
(
id
)
job
,
err
:=
c
.
A
pp
.
GetComplianceReport
(
id
)
if
err
!=
nil
{
c
.
Err
=
err
return
...
...
@@ -221,7 +221,7 @@ func getAnalytics(c *Context, w http.ResponseWriter, r *http.Request) {
teamId
:=
params
[
"id"
]
name
:=
params
[
"name"
]
rows
,
err
:=
a
pp
.
GetAnalytics
(
name
,
teamId
)
rows
,
err
:=
c
.
A
pp
.
GetAnalytics
(
name
,
teamId
)
if
err
!=
nil
{
c
.
Err
=
err
return
...
...
@@ -316,7 +316,7 @@ func adminResetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if
err
:=
a
pp
.
UpdatePasswordByUserIdSendEmail
(
userId
,
newPassword
,
c
.
T
(
"api.user.reset_password.method"
));
err
!=
nil
{
if
err
:=
c
.
A
pp
.
UpdatePasswordByUserIdSendEmail
(
userId
,
newPassword
,
c
.
T
(
"api.user.reset_password.method"
));
err
!=
nil
{
c
.
Err
=
err
return
}
...
...
@@ -412,7 +412,7 @@ func samlCertificateStatus(c *Context, w http.ResponseWriter, r *http.Request) {
}
func
getRecentlyActiveUsers
(
c
*
Context
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
profiles
,
err
:=
a
pp
.
GetRecentlyActiveUsersForTeam
(
c
.
TeamId
);
err
!=
nil
{
if
profiles
,
err
:=
c
.
A
pp
.
GetRecentlyActiveUsersForTeam
(
c
.
TeamId
);
err
!=
nil
{
c
.
Err
=
err
return
}
else
{
...
...
api/admin_test.go
View file @
1adfd0e9
...
...
@@ -8,7 +8,6 @@ import (
"strings"
"testing"
"github.com/mattermost/platform/app"
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/store"
"github.com/mattermost/platform/utils"
...
...
@@ -597,7 +596,7 @@ func TestAdminResetPassword(t *testing.T) {
user
:=
&
model
.
User
{
Email
:
strings
.
ToLower
(
model
.
NewId
())
+
"success+test@simulator.amazonses.com"
,
Nickname
:
"Corey Hulen"
,
Password
:
"passwd1"
}
user
=
Client
.
Must
(
Client
.
CreateUser
(
user
,
""
))
.
Data
.
(
*
model
.
User
)
LinkUserToTeam
(
user
,
team
)
store
.
Must
(
a
pp
.
Srv
.
Store
.
User
()
.
VerifyEmail
(
user
.
Id
))
store
.
Must
(
th
.
A
pp
.
Srv
.
Store
.
User
()
.
VerifyEmail
(
user
.
Id
))
if
_
,
err
:=
Client
.
AdminResetPassword
(
""
,
"newpwd1"
);
err
==
nil
{
t
.
Fatal
(
"Should have errored - empty user id"
)
...
...
@@ -619,7 +618,7 @@ func TestAdminResetPassword(t *testing.T) {
user2
:=
&
model
.
User
{
Email
:
strings
.
ToLower
(
model
.
NewId
())
+
"success+test@simulator.amazonses.com"
,
Nickname
:
"Corey Hulen"
,
AuthData
:
&
authData
,
AuthService
:
"random"
}
user2
=
Client
.
Must
(
Client
.
CreateUser
(
user2
,
""
))
.
Data
.
(
*
model
.
User
)
LinkUserToTeam
(
user2
,
team
)
store
.
Must
(
a
pp
.
Srv
.
Store
.
User
()
.
VerifyEmail
(
user2
.
Id
))
store
.
Must
(
th
.
A
pp
.
Srv
.
Store
.
User
()
.
VerifyEmail
(
user2
.
Id
))
if
_
,
err
:=
Client
.
AdminResetPassword
(
user
.
Id
,
"newpwd1"
);
err
!=
nil
{
t
.
Fatal
(
err
)
...
...
api/api.go
View file @
1adfd0e9
...
...
@@ -60,14 +60,14 @@ type Routes struct {
var
BaseRoutes
*
Routes
func
InitRouter
()
{
app
.
Srv
.
Router
=
mux
.
NewRouter
()
app
.
Srv
.
Router
.
NotFoundHandler
=
http
.
HandlerFunc
(
Handle404
)
app
.
Global
()
.
Srv
.
Router
=
mux
.
NewRouter
()
app
.
Global
()
.
Srv
.
Router
.
NotFoundHandler
=
http
.
HandlerFunc
(
Handle404
)
}
func
InitApi
()
{
BaseRoutes
=
&
Routes
{}
BaseRoutes
.
Root
=
app
.
Srv
.
Router
BaseRoutes
.
ApiRoot
=
app
.
Srv
.
Router
.
PathPrefix
(
model
.
API_URL_SUFFIX_V3
)
.
Subrouter
()
BaseRoutes
.
Root
=
app
.
Global
()
.
Srv
.
Router
BaseRoutes
.
ApiRoot
=
app
.
Global
()
.
Srv
.
Router
.
PathPrefix
(
model
.
API_URL_SUFFIX_V3
)
.
Subrouter
()
BaseRoutes
.
Users
=
BaseRoutes
.
ApiRoot
.
PathPrefix
(
"/users"
)
.
Subrouter
()
BaseRoutes
.
NeedUser
=
BaseRoutes
.
Users
.
PathPrefix
(
"/{user_id:[A-Za-z0-9]+}"
)
.
Subrouter
()
BaseRoutes
.
Teams
=
BaseRoutes
.
ApiRoot
.
PathPrefix
(
"/teams"
)
.
Subrouter
()
...
...
@@ -111,7 +111,7 @@ func InitApi() {
InitDeprecated
()
// 404 on any api route before web.go has a chance to serve it
app
.
Srv
.
Router
.
Handle
(
"/api/{anything:.*}"
,
http
.
HandlerFunc
(
Handle404
))
app
.
Global
()
.
Srv
.
Router
.
Handle
(
"/api/{anything:.*}"
,
http
.
HandlerFunc
(
Handle404
))
utils
.
InitHTML
()
...
...
api/apitestlib.go
View file @
1adfd0e9
...
...
@@ -17,6 +17,8 @@ import (
)
type
TestHelper
struct
{
App
*
app
.
App
BasicClient
*
model
.
Client
BasicTeam
*
model
.
Team
BasicUser
*
model
.
User
...
...
@@ -32,7 +34,7 @@ type TestHelper struct {
}
func
SetupEnterprise
()
*
TestHelper
{
if
app
.
Srv
==
nil
{
if
app
.
Global
()
.
Srv
==
nil
{
utils
.
TranslationsPreInit
()
utils
.
LoadConfig
(
"config.json"
)
utils
.
InitTranslations
(
utils
.
Cfg
.
LocalizationSettings
)
...
...
@@ -40,17 +42,17 @@ func SetupEnterprise() *TestHelper {
*
utils
.
Cfg
.
RateLimitSettings
.
Enable
=
false
utils
.
DisableDebugLogForTest
()
utils
.
License
()
.
Features
.
SetDefaults
()
app
.
NewServer
()
app
.
InitStores
()
app
.
Global
()
.
NewServer
()
app
.
Global
()
.
InitStores
()
InitRouter
()
wsapi
.
InitRouter
()
app
.
StartServer
()
app
.
Global
()
.
StartServer
()
utils
.
InitHTML
()
api4
.
InitApi
(
false
)
InitApi
()
wsapi
.
InitApi
()
utils
.
EnableDebugLogForTest
()
app
.
Srv
.
Store
.
MarkSystemRanUnitTests
()
app
.
Global
()
.
Srv
.
Store
.
MarkSystemRanUnitTests
()
*
utils
.
Cfg
.
TeamSettings
.
EnableOpenServer
=
true
}
...
...
@@ -59,7 +61,7 @@ func SetupEnterprise() *TestHelper {
}
func
Setup
()
*
TestHelper
{
if
app
.
Srv
==
nil
{
if
app
.
Global
()
.
Srv
==
nil
{
utils
.
TranslationsPreInit
()
utils
.
LoadConfig
(
"config.json"
)
utils
.
InitTranslations
(
utils
.
Cfg
.
LocalizationSettings
)
...
...
@@ -70,16 +72,16 @@ func Setup() *TestHelper {
utils
.
Cfg
.
EmailSettings
.
SMTPPort
=
"2500"
utils
.
Cfg
.
EmailSettings
.
FeedbackEmail
=
"test@example.com"
utils
.
DisableDebugLogForTest
()
app
.
NewServer
()
app
.
InitStores
()
app
.
Global
()
.
NewServer
()
app
.
Global
()
.
InitStores
()
InitRouter
()
wsapi
.
InitRouter
()
app
.
StartServer
()
app
.
Global
()
.
StartServer
()
api4
.
InitApi
(
false
)
InitApi
()
wsapi
.
InitApi
()
utils
.
EnableDebugLogForTest
()
app
.
Srv
.
Store
.
MarkSystemRanUnitTests
()
app
.
Global
()
.
Srv
.
Store
.
MarkSystemRanUnitTests
()
*
utils
.
Cfg
.
TeamSettings
.
EnableOpenServer
=
true
}
...
...
@@ -100,6 +102,7 @@ func ReloadConfigForSetup() {
}
func
(
me
*
TestHelper
)
InitBasic
()
*
TestHelper
{
me
.
App
=
app
.
Global
()
me
.
BasicClient
=
me
.
CreateClient
()
me
.
BasicUser
=
me
.
CreateUser
(
me
.
BasicClient
)
me
.
LoginBasic
()
...
...
@@ -119,6 +122,7 @@ func (me *TestHelper) InitBasic() *TestHelper {
}
func
(
me
*
TestHelper
)
InitSystemAdmin
()
*
TestHelper
{
me
.
App
=
app
.
Global
()
me
.
SystemAdminClient
=
me
.
CreateClient
()
me
.
SystemAdminUser
=
me
.
CreateUser
(
me
.
SystemAdminClient
)
me
.
SystemAdminUser
.
Password
=
"Password1"
...
...
@@ -126,7 +130,7 @@ func (me *TestHelper) InitSystemAdmin() *TestHelper {
me
.
SystemAdminTeam
=
me
.
CreateTeam
(
me
.
SystemAdminClient
)
LinkUserToTeam
(
me
.
SystemAdminUser
,
me
.
SystemAdminTeam
)
me
.
SystemAdminClient
.
SetTeamId
(
me
.
SystemAdminTeam
.
Id
)
a
pp
.
UpdateUserRoles
(
me
.
SystemAdminUser
.
Id
,
model
.
ROLE_SYSTEM_USER
.
Id
+
" "
+
model
.
ROLE_SYSTEM_ADMIN
.
Id
)
me
.
A
pp
.
UpdateUserRoles
(
me
.
SystemAdminUser
.
Id
,
model
.
ROLE_SYSTEM_USER
.
Id
+
" "
+
model
.
ROLE_SYSTEM_ADMIN
.
Id
)
me
.
SystemAdminChannel
=
me
.
CreateChannel
(
me
.
SystemAdminClient
,
me
.
SystemAdminTeam
)
return
me
...
...
@@ -168,7 +172,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User {
utils
.
DisableDebugLogForTest
()
ruser
:=
client
.
Must
(
client
.
CreateUser
(
user
,
""
))
.
Data
.
(
*
model
.
User
)
ruser
.
Password
=
"Password1"
store
.
Must
(
app
.
Srv
.
Store
.
User
()
.
VerifyEmail
(
ruser
.
Id
))
store
.
Must
(
app
.
Global
()
.
Srv
.
Store
.
User
()
.
VerifyEmail
(
ruser
.
Id
))
utils
.
EnableDebugLogForTest
()
return
ruser
}
...
...
@@ -176,7 +180,7 @@ func (me *TestHelper) CreateUser(client *model.Client) *model.User {
func
LinkUserToTeam
(
user
*
model
.
User
,
team
*
model
.
Team
)
{
utils
.
DisableDebugLogForTest
()
err
:=
app
.
JoinUserToTeam
(
team
,
user
,
""
)
err
:=
app
.
Global
()
.
JoinUserToTeam
(
team
,
user
,
""
)
if
err
!=
nil
{
l4g
.
Error
(
err
.
Error
())
l4g
.
Close
()
...
...
@@ -191,7 +195,7 @@ func UpdateUserToTeamAdmin(user *model.User, team *model.Team) {
utils
.
DisableDebugLogForTest
()
tm
:=
&
model
.
TeamMember
{
TeamId
:
team
.
Id
,
UserId
:
user
.
Id
,
Roles
:
model
.
ROLE_TEAM_USER
.
Id
+
" "
+
model
.
ROLE_TEAM_ADMIN
.
Id
}
if
tmr
:=
<-
app
.
Srv
.
Store
.
Team
()
.
UpdateMember
(
tm
);
tmr
.
Err
!=
nil
{
if
tmr
:=
<-
app
.
Global
()
.
Srv
.
Store
.
Team
()
.
UpdateMember
(
tm
);
tmr
.
Err
!=
nil
{
utils
.
EnableDebugLogForTest
()
l4g
.
Error
(
tmr
.
Err
.
Error
())
l4g
.
Close
()
...
...
@@ -205,7 +209,7 @@ func UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
utils
.
DisableDebugLogForTest
()
tm
:=
&
model
.
TeamMember
{
TeamId
:
team
.
Id
,
UserId
:
user
.
Id
,
Roles
:
model
.
ROLE_TEAM_USER
.
Id
}
if
tmr
:=
<-
app
.
Srv
.
Store
.
Team
()
.
UpdateMember
(
tm
);
tmr
.
Err
!=
nil
{
if
tmr
:=
<-
app
.
Global
()
.
Srv
.
Store
.
Team
()
.
UpdateMember
(
tm
);
tmr
.
Err
!=
nil
{
utils
.
EnableDebugLogForTest
()
l4g
.
Error
(
tmr
.
Err
.
Error
())
l4g
.
Close
()
...
...
@@ -218,10 +222,10 @@ func UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
func
MakeUserChannelAdmin
(
user
*
model
.
User
,
channel
*
model
.
Channel
)
{
utils
.
DisableDebugLogForTest
()
if
cmr
:=
<-
app
.
Srv
.
Store
.
Channel
()
.
GetMember
(
channel
.
Id
,
user
.
Id
);
cmr
.
Err
==
nil
{
if
cmr
:=
<-
app
.
Global
()
.
Srv
.
Store
.
Channel
()
.
GetMember
(
channel
.
Id
,
user
.
Id
);
cmr
.
Err
==
nil
{
cm
:=
cmr
.
Data
.
(
*
model
.
ChannelMember
)
cm
.
Roles
=
"channel_admin channel_user"
if
sr
:=
<-
app
.
Srv
.
Store
.
Channel
()
.
UpdateMember
(
cm
);
sr
.
Err
!=
nil
{
if
sr
:=
<-
app
.
Global
()
.
Srv
.
Store
.
Channel
()
.
UpdateMember
(
cm
);
sr
.
Err
!=
nil
{
utils
.
EnableDebugLogForTest
()
panic
(
sr
.
Err
)
}
...
...
@@ -236,10 +240,10 @@ func MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
func
MakeUserChannelUser
(
user
*
model
.
User
,
channel
*
model
.
Channel
)
{
utils
.
DisableDebugLogForTest
()
if
cmr
:=
<-
app
.
Srv
.
Store
.
Channel
()
.
GetMember
(
channel
.
Id
,
user
.
Id
);
cmr
.
Err
==
nil
{
if
cmr
:=
<-
app
.
Global
()
.
Srv
.
Store
.
Channel
()
.
GetMember
(
channel
.
Id
,
user
.
Id
);
cmr
.
Err
==
nil
{
cm
:=
cmr
.
Data
.
(
*
model
.
ChannelMember
)
cm
.
Roles
=
"channel_user"
if
sr
:=
<-
app
.
Srv
.
Store
.
Channel
()
.
UpdateMember
(
cm
);
sr
.
Err
!=
nil
{
if
sr
:=
<-
app
.
Global
()
.
Srv
.
Store
.
Channel
()
.
UpdateMember
(
cm
);
sr
.
Err
!=
nil
{
utils
.
EnableDebugLogForTest
()
panic
(
sr
.
Err
)
}
...
...
@@ -323,7 +327,7 @@ func (me *TestHelper) LoginSystemAdmin() {
}
func
TearDown
()
{
if
app
.
Srv
!=
nil
{
app
.
StopServer
()
if
app
.
Global
()
.
Srv
!=
nil
{
app
.
Global
()
.
StopServer
()
}
}
api/channel.go
View file @
1adfd0e9
...
...
@@ -69,7 +69,7 @@ func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if
sc
,
err
:=
a
pp
.
CreateChannelWithUser
(
channel
,
c
.
Session
.
UserId
);
err
!=
nil
{
if
sc
,
err
:=
c
.
A
pp
.
CreateChannelWithUser
(
channel
,
c
.
Session
.
UserId
);
err
!=
nil
{
c
.
Err
=
err
return
}
else
{
...
...
@@ -92,7 +92,7 @@ func createDirectChannel(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if
sc
,
err
:=
a
pp
.
CreateDirectChannel
(
c
.
Session
.
UserId
,
userId
);
err
!=
nil
{
if
sc
,
err
:=
c
.
A
pp
.
CreateDirectChannel
(
c
.
Session
.
UserId
,
userId
);
err
!=
nil
{
c
.
Err
=
err
return
}
else
{
...
...
@@ -124,7 +124,7 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
userIds
=
append
(
userIds
,
c
.
Session
.
UserId
)
}
if
sc
,
err
:=
a
pp
.
CreateGroupChannel
(
userIds
,
c
.
Session
.
UserId
);
err
!=
nil
{
if
sc
,
err
:=
c
.
A
pp
.
CreateGroupChannel
(
userIds
,
c
.
Session
.
UserId
);
err
!=
nil
{
c
.
Err
=
err
return
}
else
{
...
...
@@ -133,12 +133,12 @@ func createGroupChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
func
CanManageChannel
(
c
*
Context
,
channel
*
model
.
Channel
)
bool
{
if
channel
.
Type
==
model
.
CHANNEL_OPEN
&&
!
a
pp
.
SessionHasPermissionToChannel
(
c
.
Session
,
channel
.
Id
,
model
.
PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES
)
{
if
channel
.
Type
==
model
.
CHANNEL_OPEN
&&
!
c
.
A
pp
.
SessionHasPermissionToChannel
(
c
.
Session
,
channel
.
Id
,
model
.
PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES
)
{
c
.
SetPermissionError
(
model
.
PERMISSION_MANAGE_PUBLIC_CHANNEL_PROPERTIES
)
return
false
}
if
channel
.
Type
==
model
.
CHANNEL_PRIVATE
&&
!
a
pp
.
SessionHasPermissionToChannel
(
c
.
Session
,
channel
.
Id
,
model
.
PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES
)
{
if
channel
.
Type
==
model
.
CHANNEL_PRIVATE
&&
!
c
.
A
pp
.
SessionHasPermissionToChannel
(
c
.
Session
,
channel
.
Id
,
model
.
PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES
)
{
c
.
SetPermissionError
(
model
.
PERMISSION_MANAGE_PRIVATE_CHANNEL_PROPERTIES
)
return
false
}
...
...
@@ -157,12 +157,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var
oldChannel
*
model
.
Channel
var
err
*
model
.
AppError
if
oldChannel
,
err
=
a
pp
.
GetChannel
(
channel
.
Id
);
err
!=
nil
{
if
oldChannel
,
err
=
c
.
A
pp
.
GetChannel
(
channel
.
Id
);
err
!=
nil
{
c
.
Err
=
err
return
}
if
_
,
err
=
a
pp
.
GetChannelMember
(
channel
.
Id
,
c
.
Session
.
UserId
);
err
!=
nil
{
if
_
,
err
=
c
.
A
pp
.
GetChannelMember
(
channel
.
Id
,
c
.
Session
.
UserId
);
err
!=
nil
{
c
.
Err
=
err
return
}
...
...
@@ -200,12 +200,12 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannel
.
Type
=
channel
.
Type
}
if
_
,
err
:=
a
pp
.
UpdateChannel
(
oldChannel
);
err
!=
nil
{
if
_
,
err
:=
c
.
A
pp
.
UpdateChannel
(
oldChannel
);
err
!=
nil
{
c
.
Err
=
err
return
}
else
{
if
oldChannelDisplayName
!=
channel
.
DisplayName
{
if
err
:=
a
pp
.
PostUpdateChannelDisplayNameMessage
(
c
.
Session
.
UserId
,
channel
,
oldChannelDisplayName
,
channel
.
DisplayName
);
err
!=
nil
{
if
err
:=
c
.
A
pp
.
PostUpdateChannelDisplayNameMessage
(
c
.
Session
.
UserId
,
channel
,
oldChannelDisplayName
,
channel
.
DisplayName
);
err
!=
nil
{
l4g
.
Error
(
err
.
Error
())
}
}
...
...
@@ -232,12 +232,12 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
var
channel
*
model
.
Channel
var
err
*
model
.
AppError
if
channel
,
err
=
a
pp
.
GetChannel
(
channelId
);
err
!=
nil
{
if
channel
,
err
=
c
.
A
pp
.
GetChannel
(
channelId
);
err
!=
nil
{
c
.
Err
=
err
return
}
if
_
,
err
=
a
pp
.
GetChannelMember
(
channelId
,
c
.
Session
.
UserId
);
err
!=
nil
{
if
_
,
err
=
c
.
A
pp
.
GetChannelMember
(
channelId
,
c
.
Session
.
UserId
);
err
!=
nil
{
c
.
Err
=
err
return
}
...
...
@@ -249,11 +249,11 @@ func updateChannelHeader(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannelHeader
:=
channel
.
Header
channel
.
Header
=
channelHeader
if
_
,
err
:=
a
pp
.
UpdateChannel
(
channel
);
err
!=
nil
{
if
_
,
err
:=
c
.
A
pp
.
UpdateChannel
(
channel
);
err
!=
nil
{
c
.
Err
=
err
return
}
else
{
if
err
:=
a
pp
.
PostUpdateChannelHeaderMessage
(
c
.
Session
.
UserId
,
channel
,
oldChannelHeader
,
channelHeader
);
err
!=
nil
{
if
err
:=
c
.
A
pp
.
PostUpdateChannelHeaderMessage
(
c
.
Session
.
UserId
,
channel
,
oldChannelHeader
,
channelHeader
);
err
!=
nil
{
l4g
.
Error
(
err
.
Error
())
}
c
.
LogAudit
(
"name="
+
channel
.
Name
)
...
...
@@ -278,12 +278,12 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
var
channel
*
model
.
Channel
var
err
*
model
.
AppError
if
channel
,
err
=
a
pp
.
GetChannel
(
channelId
);
err
!=
nil
{
if
channel
,
err
=
c
.
A
pp
.
GetChannel
(
channelId
);
err
!=
nil
{
c
.
Err
=
err
return
}
if
_
,
err
=
a
pp
.
GetChannelMember
(
channelId
,
c
.
Session
.
UserId
);
err
!=
nil
{
if
_
,
err
=
c
.
A
pp
.
GetChannelMember
(
channelId
,
c
.
Session
.
UserId
);
err
!=
nil
{
c
.
Err
=
err
return
}
...
...
@@ -295,11 +295,11 @@ func updateChannelPurpose(c *Context, w http.ResponseWriter, r *http.Request) {
oldChannelPurpose
:=
channel
.
Purpose
channel
.
Purpose
=
channelPurpose
if
_
,
err
:=
a
pp
.
UpdateChannel
(
channel
);
err
!=
nil
{
if
_
,
err
:=
c
.
A
pp
.
UpdateChannel
(
channel
);
err
!=
nil
{
c
.
Err
=
err
return
}
else
{
if
err
:=
a
pp
.
PostUpdateChannelPurposeMessage
(
c
.
Session
.
UserId
,
channel
,
oldChannelPurpose
,
channelPurpose
);
err
!=
nil
{
if
err
:=
c
.
A
pp
.
PostUpdateChannelPurposeMessage
(
c
.
Session
.
UserId
,
channel
,
oldChannelPurpose
,
channelPurpose
);
err
!=
nil
{
l4g
.
Error
(
err
.
Error
())
}
c
.
LogAudit
(
"name="
+
channel
.
Name
)
...
...
@@ -315,10 +315,10 @@ func getChannels(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
// Get's all channels the user is a member of
if
channels
,
err
:=
a
pp
.
GetChannelsForUser
(
c
.
TeamId
,
c
.
Session
.
UserId
);
err
!=
nil
{
if
channels
,
err
:=
c
.
A
pp
.
GetChannelsForUser
(
c
.
TeamId
,
c
.
Session
.
UserId
);
err
!=
nil
{
if
err
.
Id
==
"store.sql_channel.get_channels.not_found.app_error"
{
// lets make sure the user is valid
if
_
,
err
:=
a
pp
.
GetUser
(
c
.
Session
.
UserId
);
err
!=
nil
{
if
_
,
err
:=
c
.
A
pp
.
GetUser
(
c
.
Session
.
UserId
);
err
!=
nil
{
c
.
Err
=
err
c
.
RemoveSessionCookie
(
w
,
r
)
l4g
.
Error
(
utils
.
T
(
"api.channel.get_channels.error"
),
c
.
Session
.
UserId
)
...
...
@@ -356,7 +356,7 @@ func getMoreChannelsPage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if
channels
,
err
:=
a
pp
.
GetChannelsUserNotIn
(
c
.
TeamId
,
c
.
Session
.
UserId
,
offset
,
limit
);
err
!=
nil
{
if
channels
,
err
:=
c
.
A
pp
.
GetChannelsUserNotIn
(
c
.
TeamId
,
c
.
Session
.
UserId
,
offset
,
limit
);
err
!=
nil
{
c
.
Err
=
err
return
}
else
{
...
...
@@ -369,7 +369,7 @@ func getChannelCounts(c *Context, w http.ResponseWriter, r *http.Request) {
// user is already in the team
if
counts
,
err
:=
a
pp
.
GetChannelCounts
(
c
.
TeamId
,
c
.
Session
.
UserId
);
err
!=
nil
{
if
counts
,
err
:=
c
.
A
pp
.
GetChannelCounts
(
c
.
TeamId
,
c
.
Session
.
UserId
);
err
!=
nil
{
c
.
Err
=
model
.
NewAppError
(
"getChannelCounts"
,
"api.channel.get_channel_counts.app_error"
,
nil
,
err
.
Message
,
http
.
StatusInternalServerError
)
return
}
else
if
HandleEtag
(
counts
.
Etag
(),
"Get Channel Counts"
,
w
,
r
)
{
...
...
@@ -389,9 +389,9 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) {
var
channel
*
model
.
Channel
var
err
*
model
.
AppError
if
channelId
!=
""
{
channel
,
err
=
a
pp
.
GetChannel
(
channelId
)
channel
,
err
=
c
.
A
pp
.
GetChannel
(
channelId
)
}
else
if
channelName
!=
""
{
channel
,
err
=
a
pp
.
GetChannelByName
(
channelName
,
c
.
TeamId
)
channel
,
err
=
c
.
A
pp
.
GetChannelByName
(
channelName
,
c
.
TeamId
)
}
else
{
c
.
SetInvalidParam
(
"join"
,
"channel_id, channel_name"
)
return
...
...
@@ -409,7 +409,7 @@ func join(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
if
err
=
a
pp
.
JoinChannel
(
channel
,
c
.
Session
.
UserId
);
err
!=
nil
{
if
err
=
c
.
A
pp
.
JoinChannel
(
channel
,
c
.
Session
.
UserId
);
err
!=
nil
{
c
.
Err
=
err
return
}
...
...
@@ -422,7 +422,7 @@ func leave(c *Context, w http.ResponseWriter, r *http.Request) {
params
:=
mux
.
Vars
(
r
)
id
:=
params
[
"channel_id"
]
err
:=
a
pp
.
LeaveChannel
(
id
,
c
.
Session
.
UserId
)
err
:=
c
.
A
pp
.
LeaveChannel
(
id
,
c
.
Session
.
UserId
)
if
err
!=
nil
{
c
.
Err
=
err
return
...
...
@@ -440,22 +440,22 @@ func deleteChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var
channel
*
model
.
Channel
var
err
*
model
.
AppError
if
channel
,
err
=
a
pp
.
GetChannel
(
id
);
err
!=
nil
{
if
channel
,
err
=
c
.
A
pp
.
GetChannel
(
id
);
err
!=
nil
{
c
.
Err
=
err
return
}
if
channel
.
Type
==
model
.
CHANNEL_OPEN
&&
!
a
pp
.
SessionHasPermissionToChannel
(
c
.
Session
,
channel
.
Id
,
model
.
PERMISSION_DELETE_PUBLIC_CHANNEL
)
{
if
channel
.
Type
==
model
.
CHANNEL_OPEN
&&
!
c
.
A
pp
.
SessionHasPermissionToChannel
(
c
.
Session
,
channel
.
Id
,
model
.
PERMISSION_DELETE_PUBLIC_CHANNEL
)
{
c
.
SetPermissionError
(
model
.
PERMISSION_DELETE_PUBLIC_CHANNEL
)
return
}
if
channel
.
Type
==
model
.
CHANNEL_PRIVATE
&&
!
a
pp
.
SessionHasPermissionToChannel
(
c
.
Session
,
channel
.
Id
,
model
.
PERMISSION_DELETE_PRIVATE_CHANNEL
)
{
if
channel
.
Type
==
model
.
CHANNEL_PRIVATE
&&
!
c
.
A
pp
.
SessionHasPermissionToChannel
(
c
.
Session
,
channel
.
Id
,
model
.
PERMISSION_DELETE_PRIVATE_CHANNEL
)
{
c
.
SetPermissionError
(
model
.
PERMISSION_DELETE_PRIVATE_CHANNEL
)
return
}
err
=
a
pp
.
DeleteChannel
(
channel
,
c
.
Session
.
UserId
)
err
=
c
.
A
pp
.
DeleteChannel
(
channel
,
c
.
Session
.
UserId
)
if
err
!=
nil
{
c
.
Err
=
err
return
...
...
@@ -474,7 +474,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
var
channel
*
model
.
Channel
var
err
*
model
.
AppError
if
channel
,
err
=
a
pp
.
GetChannel
(
id
);
err
!=
nil
{
if
channel
,
err
=
c
.
A
pp
.
GetChannel
(
id
);
err
!=
nil
{
c
.
Err
=
err
return
}
...
...
@@ -485,7 +485,7 @@ func getChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
var
member
*
model
.
ChannelMember
if
member
,
err
=
a
pp
.
GetChannelMember
(
id
,
c
.
Session
.
UserId
);
err
!=
nil
{
if
member
,
err
=
c
.
A
pp
.
GetChannelMember
(
id
,
c
.
Session
.
UserId
);
err
!=
nil
{
c
.
Err
=
err
return
}
...
...
@@ -506,11 +506,11 @@ func getChannelByName(c *Context, w http.ResponseWriter, r *http.Request) {
params
:=
mux
.
Vars
(
r
)
channelName
:=
params
[
"channel_name"
]
if
channel
,
err
:=
a
pp
.
GetChannelByName
(
channelName
,
c
.
TeamId
);
err
!=
nil
{
if
channel
,
err
:=
c
.
A
pp
.
GetChannelByName
(
channelName
,
c
.
TeamId
);
err
!=
nil
{
c
.
Err
=
err
return
}
else
{
if
!
a
pp
.
SessionHasPermissionToChannel
(
c
.
Session
,
channel
.
Id
,
model
.
PERMISSION_READ_CHANNEL
)
{
if
!
c
.
A
pp
.
SessionHasPermissionToChannel
(
c
.
Session
,
channel
.
Id
,
model
.
PERMISSION_READ_CHANNEL
)
{
c
.
SetPermissionError
(
model
.
PERMISSION_READ_CHANNEL
)
return
}
...
...
@@ -535,7 +535,7 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) {