MM-21898 - Part 1: Generate and use an interface instead of *A… (#13840)

* Generate and use an interface instead of *App
Этот коммит содержится в:
Eli Yukelzon
2020-02-13 13:26:58 +01:00
коммит произвёл GitHub
родитель 66fc096768
Коммит 17523fa5d9
200 изменённых файлов: 4553 добавлений и 2361 удалений

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

@@ -98,7 +98,7 @@ func createUser(c *Context, w http.ResponseWriter, r *http.Request) {
var err *model.AppError
if len(tokenId) > 0 {
var token *model.Token
token, err = c.App.Srv.Store.Token().GetByToken(tokenId)
token, err = c.App.Srv().Store.Token().GetByToken(tokenId)
if err != nil {
c.Err = model.NewAppError("CreateUserWithToken", "api.user.create_user.signup_link_invalid.app_error", nil, err.Error(), http.StatusBadRequest)
return
@@ -138,7 +138,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, c.Params.UserId)
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, c.Params.UserId)
if err != nil {
c.SetPermissionError(model.PERMISSION_VIEW_MEMBERS)
return
@@ -155,7 +155,7 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.IsSystemAdmin() || c.App.Session.UserId == user.Id {
if c.IsSystemAdmin() || c.App.Session().UserId == user.Id {
userTermsOfService, err := c.App.GetUserTermsOfService(user.Id)
if err != nil && err.StatusCode != http.StatusNotFound {
c.Err = err
@@ -174,12 +174,12 @@ func getUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Session.UserId == user.Id {
if c.App.Session().UserId == user.Id {
user.Sanitize(map[string]bool{})
} else {
c.App.SanitizeProfile(user, c.IsSystemAdmin())
}
c.App.UpdateLastActivityAtIfNeeded(c.App.Session)
c.App.UpdateLastActivityAtIfNeeded(*c.App.Session())
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
w.Write([]byte(user.ToJson()))
}
@@ -192,7 +192,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
user, err := c.App.GetUserByUsername(c.Params.Username)
if err != nil {
restrictions, err2 := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
restrictions, err2 := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
if err2 != nil {
c.Err = err2
return
@@ -205,7 +205,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, user.Id)
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, user.Id)
if err != nil {
c.Err = err
return
@@ -216,7 +216,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.IsSystemAdmin() || c.App.Session.UserId == user.Id {
if c.IsSystemAdmin() || c.App.Session().UserId == user.Id {
userTermsOfService, err := c.App.GetUserTermsOfService(user.Id)
if err != nil && err.StatusCode != http.StatusNotFound {
c.Err = err
@@ -235,7 +235,7 @@ func getUserByUsername(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Session.UserId == user.Id {
if c.App.Session().UserId == user.Id {
user.Sanitize(map[string]bool{})
} else {
c.App.SanitizeProfile(user, c.IsSystemAdmin())
@@ -252,13 +252,13 @@ func getUserByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
sanitizeOptions := c.App.GetSanitizeOptions(c.IsSystemAdmin())
if !sanitizeOptions["email"] {
c.Err = model.NewAppError("getUserByEmail", "api.user.get_user_by_email.permissions.app_error", nil, "userId="+c.App.Session.UserId, http.StatusForbidden)
c.Err = model.NewAppError("getUserByEmail", "api.user.get_user_by_email.permissions.app_error", nil, "userId="+c.App.Session().UserId, http.StatusForbidden)
return
}
user, err := c.App.GetUserByEmail(c.Params.Email)
if err != nil {
restrictions, err2 := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
restrictions, err2 := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
if err2 != nil {
c.Err = err2
return
@@ -271,7 +271,7 @@ func getUserByEmail(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, user.Id)
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, user.Id)
if err != nil {
c.Err = err
return
@@ -299,7 +299,7 @@ func getDefaultProfileImage(c *Context, w http.ResponseWriter, r *http.Request)
return
}
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, c.Params.UserId)
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, c.Params.UserId)
if err != nil {
c.Err = err
return
@@ -333,7 +333,7 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session.UserId, c.Params.UserId)
canSee, err := c.App.UserCanSeeOtherUser(c.App.Session().UserId, c.Params.UserId)
if err != nil {
c.Err = err
return
@@ -380,7 +380,7 @@ func setProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -428,7 +428,7 @@ func setDefaultProfileImage(c *Context, w http.ResponseWriter, r *http.Request)
return
}
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -458,7 +458,7 @@ func getTotalUsersStats(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
if err != nil {
c.Err = err
return
@@ -527,7 +527,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
groupConstrainedBool, _ := strconv.ParseBool(groupConstrained)
inactiveBool, _ := strconv.ParseBool(inactive)
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
if err != nil {
c.Err = err
return
@@ -553,21 +553,21 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
if withoutTeamBool, _ := strconv.ParseBool(withoutTeam); withoutTeamBool {
// Use a special permission for now
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_LIST_USERS_WITHOUT_TEAM) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_LIST_USERS_WITHOUT_TEAM) {
c.SetPermissionError(model.PERMISSION_LIST_USERS_WITHOUT_TEAM)
return
}
profiles, err = c.App.GetUsersWithoutTeamPage(userGetOptions, c.IsSystemAdmin())
} else if len(notInChannelId) > 0 {
if !c.App.SessionHasPermissionToChannel(c.App.Session, notInChannelId, model.PERMISSION_READ_CHANNEL) {
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), notInChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
profiles, err = c.App.GetUsersNotInChannelPage(inTeamId, notInChannelId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
} else if len(notInTeamId) > 0 {
if !c.App.SessionHasPermissionToTeam(c.App.Session, notInTeamId, model.PERMISSION_VIEW_TEAM) {
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), notInTeamId, model.PERMISSION_VIEW_TEAM) {
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
return
}
@@ -579,7 +579,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
profiles, err = c.App.GetUsersNotInTeamPage(notInTeamId, groupConstrainedBool, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin(), restrictions)
} else if len(inTeamId) > 0 {
if !c.App.SessionHasPermissionToTeam(c.App.Session, inTeamId, model.PERMISSION_VIEW_TEAM) {
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), inTeamId, model.PERMISSION_VIEW_TEAM) {
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
return
}
@@ -596,7 +596,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
profiles, err = c.App.GetUsersInTeamPage(userGetOptions, c.IsSystemAdmin())
}
} else if len(inChannelId) > 0 {
if !c.App.SessionHasPermissionToChannel(c.App.Session, inChannelId, model.PERMISSION_READ_CHANNEL) {
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), inChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
@@ -606,7 +606,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
profiles, err = c.App.GetUsersInChannelPage(inChannelId, c.Params.Page, c.Params.PerPage, c.IsSystemAdmin())
}
} else {
userGetOptions, err = c.App.RestrictUsersGetByPermissions(c.App.Session.UserId, userGetOptions)
userGetOptions, err = c.App.RestrictUsersGetByPermissions(c.App.Session().UserId, userGetOptions)
if err != nil {
c.Err = err
return
@@ -622,7 +622,7 @@ func getUsers(c *Context, w http.ResponseWriter, r *http.Request) {
if len(etag) > 0 {
w.Header().Set(model.HEADER_ETAG_SERVER, etag)
}
c.App.UpdateLastActivityAtIfNeeded(c.App.Session)
c.App.UpdateLastActivityAtIfNeeded(*c.App.Session())
w.Write([]byte(model.UserListToJson(profiles)))
}
@@ -649,7 +649,7 @@ func getUsersByIds(c *Context, w http.ResponseWriter, r *http.Request) {
options.Since = since
}
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
if err != nil {
c.Err = err
return
@@ -673,7 +673,7 @@ func getUsersByNames(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session.UserId)
restrictions, err := c.App.GetViewUsersRestrictions(c.App.Session().UserId)
if err != nil {
c.Err = err
return
@@ -705,22 +705,22 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if props.InChannelId != "" && !c.App.SessionHasPermissionToChannel(c.App.Session, props.InChannelId, model.PERMISSION_READ_CHANNEL) {
if props.InChannelId != "" && !c.App.SessionHasPermissionToChannel(*c.App.Session(), props.InChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
if props.NotInChannelId != "" && !c.App.SessionHasPermissionToChannel(c.App.Session, props.NotInChannelId, model.PERMISSION_READ_CHANNEL) {
if props.NotInChannelId != "" && !c.App.SessionHasPermissionToChannel(*c.App.Session(), props.NotInChannelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
if props.TeamId != "" && !c.App.SessionHasPermissionToTeam(c.App.Session, props.TeamId, model.PERMISSION_VIEW_TEAM) {
if props.TeamId != "" && !c.App.SessionHasPermissionToTeam(*c.App.Session(), props.TeamId, model.PERMISSION_VIEW_TEAM) {
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
return
}
if props.NotInTeamId != "" && !c.App.SessionHasPermissionToTeam(c.App.Session, props.NotInTeamId, model.PERMISSION_VIEW_TEAM) {
if props.NotInTeamId != "" && !c.App.SessionHasPermissionToTeam(*c.App.Session(), props.NotInTeamId, model.PERMISSION_VIEW_TEAM) {
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
return
}
@@ -738,7 +738,7 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
Role: props.Role,
}
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
options.AllowEmails = true
options.AllowFullNames = true
} else {
@@ -746,7 +746,7 @@ func searchUsers(c *Context, w http.ResponseWriter, r *http.Request) {
options.AllowFullNames = *c.App.Config().PrivacySettings.ShowFullName
}
options, err := c.App.RestrictUsersSearchByPermissions(c.App.Session.UserId, options)
options, err := c.App.RestrictUsersSearchByPermissions(c.App.Session().UserId, options)
if err != nil {
c.Err = err
return
@@ -780,21 +780,21 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
Limit: limit,
}
if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
options.AllowFullNames = true
} else {
options.AllowFullNames = *c.App.Config().PrivacySettings.ShowFullName
}
if len(channelId) > 0 {
if !c.App.SessionHasPermissionToChannel(c.App.Session, channelId, model.PERMISSION_READ_CHANNEL) {
if !c.App.SessionHasPermissionToChannel(*c.App.Session(), channelId, model.PERMISSION_READ_CHANNEL) {
c.SetPermissionError(model.PERMISSION_READ_CHANNEL)
return
}
}
if len(teamId) > 0 {
if !c.App.SessionHasPermissionToTeam(c.App.Session, teamId, model.PERMISSION_VIEW_TEAM) {
if !c.App.SessionHasPermissionToTeam(*c.App.Session(), teamId, model.PERMISSION_VIEW_TEAM) {
c.SetPermissionError(model.PERMISSION_VIEW_TEAM)
return
}
@@ -803,7 +803,7 @@ func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) {
var autocomplete model.UserAutocomplete
var err *model.AppError
options, err = c.App.RestrictUsersSearchByPermissions(c.App.Session.UserId, options)
options, err = c.App.RestrictUsersSearchByPermissions(c.App.Session().UserId, options)
if err != nil {
c.Err = err
return
@@ -859,7 +859,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionToUser(c.App.Session, user.Id) {
if !c.App.SessionHasPermissionToUser(*c.App.Session(), user.Id) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -870,7 +870,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Session.IsOAuth {
if c.App.Session().IsOAuth {
if ouser.Email != user.Email {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
c.Err.DetailedError += ", attempted email update by oauth app"
@@ -879,7 +879,7 @@ func updateUser(c *Context, w http.ResponseWriter, r *http.Request) {
}
// If eMail update is attempted by the currently logged in user, check if correct password was provided
if user.Email != "" && ouser.Email != user.Email && c.App.Session.UserId == c.Params.UserId {
if user.Email != "" && ouser.Email != user.Email && c.App.Session().UserId == c.Params.UserId {
err = c.App.DoubleCheckPassword(ouser, user.Password)
if err != nil {
c.SetInvalidParam("password")
@@ -909,7 +909,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -920,7 +920,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Session.IsOAuth && patch.Email != nil {
if c.App.Session().IsOAuth && patch.Email != nil {
if ouser.Email != *patch.Email {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
c.Err.DetailedError += ", attempted email update by oauth app"
@@ -929,7 +929,7 @@ func patchUser(c *Context, w http.ResponseWriter, r *http.Request) {
}
// If eMail update is attempted by the currently logged in user, check if correct password was provided
if patch.Email != nil && ouser.Email != *patch.Email && c.App.Session.UserId == c.Params.UserId {
if patch.Email != nil && ouser.Email != *patch.Email && c.App.Session().UserId == c.Params.UserId {
if patch.Password == nil {
c.SetInvalidParam("password")
return
@@ -960,13 +960,13 @@ func deleteUser(c *Context, w http.ResponseWriter, r *http.Request) {
userId := c.Params.UserId
if !c.App.SessionHasPermissionToUser(c.App.Session, userId) {
if !c.App.SessionHasPermissionToUser(*c.App.Session(), userId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
// if EnableUserDeactivation flag is disabled the user cannot deactivate himself.
if c.Params.UserId == c.App.Session.UserId && !*c.App.Config().TeamSettings.EnableUserDeactivation && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
if c.Params.UserId == c.App.Session().UserId && !*c.App.Config().TeamSettings.EnableUserDeactivation && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
c.Err = model.NewAppError("deleteUser", "api.user.update_active.not_enable.app_error", nil, "userId="+c.Params.UserId, http.StatusUnauthorized)
return
}
@@ -999,7 +999,7 @@ func updateUserRoles(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_ROLES) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_ROLES) {
c.SetPermissionError(model.PERMISSION_MANAGE_ROLES)
return
}
@@ -1028,9 +1028,9 @@ func updateUserActive(c *Context, w http.ResponseWriter, r *http.Request) {
}
// true when you're trying to de-activate yourself
isSelfDeactive := !active && c.Params.UserId == c.App.Session.UserId
isSelfDeactive := !active && c.Params.UserId == c.App.Session().UserId
if !isSelfDeactive && !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
if !isSelfDeactive && !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
c.Err = model.NewAppError("updateUserActive", "api.user.update_active.permissions.app_error", nil, "userId="+c.Params.UserId, http.StatusForbidden)
return
}
@@ -1058,7 +1058,7 @@ func updateUserActive(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit(fmt.Sprintf("user_id=%s active=%v", user.Id, active))
if isSelfDeactive {
c.App.Srv.Go(func() {
c.App.Srv().Go(func() {
if err = c.App.SendDeactivateAccountEmail(user.Email, user.Locale, c.App.GetSiteURL()); err != nil {
mlog.Error(err.Error())
}
@@ -1134,13 +1134,13 @@ func updateUserMfa(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Session.IsOAuth {
if c.App.Session().IsOAuth {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
c.Err.DetailedError += ", attempted access by oauth app"
return
}
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1178,13 +1178,13 @@ func generateMfaSecret(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Session.IsOAuth {
if c.App.Session().IsOAuth {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
c.Err.DetailedError += ", attempted access by oauth app"
return
}
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1213,7 +1213,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("attempted")
var err *model.AppError
if c.Params.UserId == c.App.Session.UserId {
if c.Params.UserId == c.App.Session().UserId {
currentPassword := props["current_password"]
if len(currentPassword) <= 0 {
c.SetInvalidParam("current_password")
@@ -1221,7 +1221,7 @@ func updatePassword(c *Context, w http.ResponseWriter, r *http.Request) {
}
err = c.App.UpdatePasswordAsUser(c.Params.UserId, currentPassword, newPassword)
} else if c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
} else if c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
err = c.App.UpdatePasswordByUserIdSendEmail(c.Params.UserId, newPassword, c.App.T("api.user.reset_password.method"))
} else {
err = model.NewAppError("updatePassword", "api.user.update_password.context.app_error", nil, "", http.StatusForbidden)
@@ -1431,8 +1431,8 @@ func logout(c *Context, w http.ResponseWriter, r *http.Request) {
func Logout(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
c.RemoveSessionCookie(w, r)
if c.App.Session.Id != "" {
if err := c.App.RevokeSessionById(c.App.Session.Id); err != nil {
if c.App.Session().Id != "" {
if err := c.App.RevokeSessionById(c.App.Session().Id); err != nil {
c.Err = err
return
}
@@ -1447,7 +1447,7 @@ func getSessions(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1471,7 +1471,7 @@ func revokeSession(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1508,7 +1508,7 @@ func revokeAllSessionsForUser(c *Context, w http.ResponseWriter, r *http.Request
return
}
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1522,7 +1522,7 @@ func revokeAllSessionsForUser(c *Context, w http.ResponseWriter, r *http.Request
}
func revokeAllSessionsAllUsers(c *Context, w http.ResponseWriter, r *http.Request) {
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return
}
@@ -1545,13 +1545,13 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
}
// A special case where we logout of all other sessions with the same device id
if err := c.App.RevokeSessionsForDeviceId(c.App.Session.UserId, deviceId, c.App.Session.Id); err != nil {
if err := c.App.RevokeSessionsForDeviceId(c.App.Session().UserId, deviceId, c.App.Session().Id); err != nil {
c.Err = err
return
}
c.App.ClearSessionCacheForUser(c.App.Session.UserId)
c.App.Session.SetExpireInDays(*c.App.Config().ServiceSettings.SessionLengthMobileInDays)
c.App.ClearSessionCacheForUser(c.App.Session().UserId)
c.App.Session().SetExpireInDays(*c.App.Config().ServiceSettings.SessionLengthMobileInDays)
maxAge := *c.App.Config().ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24
@@ -1565,7 +1565,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
expiresAt := time.Unix(model.GetMillis()/1000+int64(maxAge), 0)
sessionCookie := &http.Cookie{
Name: model.SESSION_COOKIE_TOKEN,
Value: c.App.Session.Token,
Value: c.App.Session().Token,
Path: subpath,
MaxAge: maxAge,
Expires: expiresAt,
@@ -1576,7 +1576,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
http.SetCookie(w, sessionCookie)
if err := c.App.AttachDeviceId(c.App.Session.Id, deviceId, c.App.Session.ExpiresAt); err != nil {
if err := c.App.AttachDeviceId(c.App.Session().Id, deviceId, c.App.Session().ExpiresAt); err != nil {
c.Err = err
return
}
@@ -1591,7 +1591,7 @@ func getUserAudits(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionToUser(c.App.Session, c.Params.UserId) {
if !c.App.SessionHasPermissionToUser(*c.App.Session(), c.Params.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1668,7 +1668,7 @@ func switchAccountType(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
link, err = c.App.SwitchOAuthToEmail(switchRequest.Email, switchRequest.NewPassword, c.App.Session.UserId)
link, err = c.App.SwitchOAuthToEmail(switchRequest.Email, switchRequest.NewPassword, c.App.Session().UserId)
} else if switchRequest.EmailToLdap() {
link, err = c.App.SwitchEmailToLdap(switchRequest.Email, switchRequest.Password, switchRequest.MfaCode, switchRequest.LdapLoginId, switchRequest.NewPassword)
} else if switchRequest.LdapToEmail() {
@@ -1693,7 +1693,7 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if c.App.Session.IsOAuth {
if c.App.Session().IsOAuth {
c.SetPermissionError(model.PERMISSION_CREATE_USER_ACCESS_TOKEN)
c.Err.DetailedError += ", attempted access by oauth app"
return
@@ -1712,12 +1712,12 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_USER_ACCESS_TOKEN) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_CREATE_USER_ACCESS_TOKEN) {
c.SetPermissionError(model.PERMISSION_CREATE_USER_ACCESS_TOKEN)
return
}
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, c.Params.UserId) {
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), c.Params.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1736,7 +1736,7 @@ func createUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
}
func searchUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request) {
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return
}
@@ -1761,7 +1761,7 @@ func searchUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request)
}
func getUserAccessTokens(c *Context, w http.ResponseWriter, r *http.Request) {
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_MANAGE_SYSTEM) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return
}
@@ -1781,12 +1781,12 @@ func getUserAccessTokensForUser(c *Context, w http.ResponseWriter, r *http.Reque
return
}
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_READ_USER_ACCESS_TOKEN) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_READ_USER_ACCESS_TOKEN) {
c.SetPermissionError(model.PERMISSION_READ_USER_ACCESS_TOKEN)
return
}
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, c.Params.UserId) {
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), c.Params.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1806,7 +1806,7 @@ func getUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_READ_USER_ACCESS_TOKEN) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_READ_USER_ACCESS_TOKEN) {
c.SetPermissionError(model.PERMISSION_READ_USER_ACCESS_TOKEN)
return
}
@@ -1817,7 +1817,7 @@ func getUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, accessToken.UserId) {
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), accessToken.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1835,7 +1835,7 @@ func revokeUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_REVOKE_USER_ACCESS_TOKEN) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_REVOKE_USER_ACCESS_TOKEN) {
c.SetPermissionError(model.PERMISSION_REVOKE_USER_ACCESS_TOKEN)
return
}
@@ -1846,7 +1846,7 @@ func revokeUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, accessToken.UserId) {
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), accessToken.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1871,7 +1871,7 @@ func disableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request)
c.LogAudit("")
// No separate permission for this action for now
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_REVOKE_USER_ACCESS_TOKEN) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_REVOKE_USER_ACCESS_TOKEN) {
c.SetPermissionError(model.PERMISSION_REVOKE_USER_ACCESS_TOKEN)
return
}
@@ -1882,7 +1882,7 @@ func disableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request)
return
}
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, accessToken.UserId) {
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), accessToken.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1907,7 +1907,7 @@ func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
c.LogAudit("")
// No separate permission for this action for now
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_CREATE_USER_ACCESS_TOKEN) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_CREATE_USER_ACCESS_TOKEN) {
c.SetPermissionError(model.PERMISSION_CREATE_USER_ACCESS_TOKEN)
return
}
@@ -1918,7 +1918,7 @@ func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionToUserOrBot(c.App.Session, accessToken.UserId) {
if !c.App.SessionHasPermissionToUserOrBot(*c.App.Session(), accessToken.UserId) {
c.SetPermissionError(model.PERMISSION_EDIT_OTHER_USERS)
return
}
@@ -1935,7 +1935,7 @@ func enableUserAccessToken(c *Context, w http.ResponseWriter, r *http.Request) {
func saveUserTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
props := model.StringInterfaceFromJson(r.Body)
userId := c.App.Session.UserId
userId := c.App.Session().UserId
termsOfServiceId := props["termsOfServiceId"].(string)
accepted := props["accepted"].(bool)
@@ -1954,7 +1954,7 @@ func saveUserTermsOfService(c *Context, w http.ResponseWriter, r *http.Request)
}
func getUserTermsOfService(c *Context, w http.ResponseWriter, r *http.Request) {
userId := c.App.Session.UserId
userId := c.App.Session().UserId
result, err := c.App.GetUserTermsOfService(userId)
if err != nil {
c.Err = err
@@ -1969,7 +1969,7 @@ func promoteGuestToUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_PROMOTE_GUEST) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_PROMOTE_GUEST) {
c.SetPermissionError(model.PERMISSION_PROMOTE_GUEST)
return
}
@@ -1985,7 +1985,7 @@ func promoteGuestToUser(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if err := c.App.PromoteGuestToUser(user, c.App.Session.UserId); err != nil {
if err := c.App.PromoteGuestToUser(user, c.App.Session().UserId); err != nil {
c.Err = err
return
}
@@ -2009,7 +2009,7 @@ func demoteUserToGuest(c *Context, w http.ResponseWriter, r *http.Request) {
return
}
if !c.App.SessionHasPermissionTo(c.App.Session, model.PERMISSION_DEMOTE_TO_GUEST) {
if !c.App.SessionHasPermissionTo(*c.App.Session(), model.PERMISSION_DEMOTE_TO_GUEST) {
c.SetPermissionError(model.PERMISSION_DEMOTE_TO_GUEST)
return
}