Migrate System store to Sync by default (#10838)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
3e6fed8df4
Коммит
f8a89a52fc
30
app/app.go
30
app/app.go
@@ -110,18 +110,19 @@ func (a *App) EnsureDiagnosticId() {
|
||||
if a.Srv.diagnosticId != "" {
|
||||
return
|
||||
}
|
||||
if result := <-a.Srv.Store.System().Get(); result.Err == nil {
|
||||
props := result.Data.(model.StringMap)
|
||||
|
||||
id := props[model.SYSTEM_DIAGNOSTIC_ID]
|
||||
if len(id) == 0 {
|
||||
id = model.NewId()
|
||||
systemId := &model.System{Name: model.SYSTEM_DIAGNOSTIC_ID, Value: id}
|
||||
<-a.Srv.Store.System().Save(systemId)
|
||||
}
|
||||
|
||||
a.Srv.diagnosticId = id
|
||||
props, err := a.Srv.Store.System().Get()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
id := props[model.SYSTEM_DIAGNOSTIC_ID]
|
||||
if len(id) == 0 {
|
||||
id = model.NewId()
|
||||
systemId := &model.System{Name: model.SYSTEM_DIAGNOSTIC_ID, Value: id}
|
||||
a.Srv.Store.System().Save(systemId)
|
||||
}
|
||||
|
||||
a.Srv.diagnosticId = id
|
||||
}
|
||||
|
||||
func (a *App) HTMLTemplates() *template.Template {
|
||||
@@ -144,11 +145,10 @@ func (a *App) Handle404(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (a *App) getSystemInstallDate() (int64, *model.AppError) {
|
||||
result := <-a.Srv.Store.System().GetByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
if result.Err != nil {
|
||||
return 0, result.Err
|
||||
systemData, appErr := a.Srv.Store.System().GetByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
if appErr != nil {
|
||||
return 0, appErr
|
||||
}
|
||||
systemData := result.Data.(*model.System)
|
||||
value, err := strconv.ParseInt(systemData.Value, 10, 64)
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("getSystemInstallDate", "app.system_install_date.parse_int.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
|
||||
@@ -113,9 +113,9 @@ func (a *App) ensurePostActionCookieSecret() error {
|
||||
|
||||
var secret *model.SystemPostActionCookieSecret
|
||||
|
||||
result := <-a.Srv.Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
if result.Err == nil {
|
||||
if err := json.Unmarshal([]byte(result.Data.(*model.System).Value), &secret); err != nil {
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
if err == nil {
|
||||
if err := json.Unmarshal([]byte(value.Value), &secret); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ func (a *App) ensurePostActionCookieSecret() error {
|
||||
return err
|
||||
}
|
||||
system.Value = string(v)
|
||||
if result = <-a.Srv.Store.System().Save(system); result.Err == nil {
|
||||
if err = a.Srv.Store.System().Save(system); err == nil {
|
||||
// If we were able to save the key, use it, otherwise ignore the error.
|
||||
secret = newSecret
|
||||
}
|
||||
@@ -147,12 +147,12 @@ func (a *App) ensurePostActionCookieSecret() error {
|
||||
// If we weren't able to save a new key above, another server must have beat us to it. Get the
|
||||
// key from the database, and if that fails, error out.
|
||||
if secret == nil {
|
||||
result := <-a.Srv.Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
if result.Err != nil {
|
||||
return result.Err
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_POST_ACTION_COOKIE_SECRET)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte(result.Data.(*model.System).Value), &secret); err != nil {
|
||||
if err := json.Unmarshal([]byte(value.Value), &secret); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -170,9 +170,9 @@ func (a *App) ensureAsymmetricSigningKey() error {
|
||||
|
||||
var key *model.SystemAsymmetricSigningKey
|
||||
|
||||
result := <-a.Srv.Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
if result.Err == nil {
|
||||
if err := json.Unmarshal([]byte(result.Data.(*model.System).Value), &key); err != nil {
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
if err == nil {
|
||||
if err := json.Unmarshal([]byte(value.Value), &key); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -199,7 +199,7 @@ func (a *App) ensureAsymmetricSigningKey() error {
|
||||
return err
|
||||
}
|
||||
system.Value = string(v)
|
||||
if result = <-a.Srv.Store.System().Save(system); result.Err == nil {
|
||||
if err = a.Srv.Store.System().Save(system); err == nil {
|
||||
// If we were able to save the key, use it, otherwise ignore the error.
|
||||
key = newKey
|
||||
}
|
||||
@@ -208,12 +208,12 @@ func (a *App) ensureAsymmetricSigningKey() error {
|
||||
// If we weren't able to save a new key above, another server must have beat us to it. Get the
|
||||
// key from the database, and if that fails, error out.
|
||||
if key == nil {
|
||||
result := <-a.Srv.Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
if result.Err != nil {
|
||||
return result.Err
|
||||
value, err := a.Srv.Store.System().GetByName(model.SYSTEM_ASYMMETRIC_SIGNING_KEY)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal([]byte(result.Data.(*model.System).Value), &key); err != nil {
|
||||
if err := json.Unmarshal([]byte(value.Value), &key); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -251,12 +251,12 @@ func (a *App) ensureInstallationDate() error {
|
||||
installationDate = utils.MillisFromTime(time.Now())
|
||||
}
|
||||
|
||||
result = <-a.Srv.Store.System().SaveOrUpdate(&model.System{
|
||||
err = a.Srv.Store.System().SaveOrUpdate(&model.System{
|
||||
Name: model.SYSTEM_INSTALLATION_DATE_KEY,
|
||||
Value: strconv.FormatInt(installationDate, 10),
|
||||
})
|
||||
if result.Err != nil {
|
||||
return result.Err
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -124,9 +124,9 @@ func TestEnsureInstallationDate(t *testing.T) {
|
||||
}
|
||||
|
||||
if tc.PrevInstallationDate == nil {
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
} else {
|
||||
<-th.App.Srv.Store.System().SaveOrUpdate(&model.System{
|
||||
th.App.Srv.Store.System().SaveOrUpdate(&model.System{
|
||||
Name: model.SYSTEM_INSTALLATION_DATE_KEY,
|
||||
Value: strconv.FormatInt(*tc.PrevInstallationDate, 10),
|
||||
})
|
||||
@@ -139,9 +139,8 @@ func TestEnsureInstallationDate(t *testing.T) {
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
|
||||
result := <-th.App.Srv.Store.System().GetByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
assert.Nil(t, result.Err)
|
||||
data, _ := result.Data.(*model.System)
|
||||
data, err := th.App.Srv.Store.System().GetByName(model.SYSTEM_INSTALLATION_DATE_KEY)
|
||||
assert.Nil(t, err)
|
||||
value, _ := strconv.ParseInt(data.Value, 10, 64)
|
||||
assert.True(t, *tc.ExpectedInstallationDate <= value && *tc.ExpectedInstallationDate+1000 >= value)
|
||||
}
|
||||
|
||||
@@ -703,12 +703,12 @@ func (a *App) trackServer() {
|
||||
|
||||
func (a *App) trackPermissions() {
|
||||
phase1Complete := false
|
||||
if ph1res := <-a.Srv.Store.System().GetByName(ADVANCED_PERMISSIONS_MIGRATION_KEY); ph1res.Err == nil {
|
||||
if _, err := a.Srv.Store.System().GetByName(ADVANCED_PERMISSIONS_MIGRATION_KEY); err == nil {
|
||||
phase1Complete = true
|
||||
}
|
||||
|
||||
phase2Complete := false
|
||||
if ph2res := <-a.Srv.Store.System().GetByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2); ph2res.Err == nil {
|
||||
if _, err := a.Srv.Store.System().GetByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2); err == nil {
|
||||
phase2Complete = true
|
||||
}
|
||||
|
||||
|
||||
@@ -22,10 +22,10 @@ func TestImportImportScheme(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
// Mark the phase 2 permissions migration as completed.
|
||||
<-th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
|
||||
defer func() {
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
}()
|
||||
|
||||
// Try importing an invalid scheme in dryRun mode.
|
||||
@@ -243,10 +243,10 @@ func TestImportImportSchemeWithoutGuestRoles(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
// Mark the phase 2 permissions migration as completed.
|
||||
<-th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
|
||||
defer func() {
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
}()
|
||||
|
||||
// Try importing an invalid scheme in dryRun mode.
|
||||
@@ -558,10 +558,10 @@ func TestImportImportTeam(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
// Mark the phase 2 permissions migration as completed.
|
||||
<-th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
|
||||
defer func() {
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
}()
|
||||
|
||||
scheme1 := th.SetupTeamScheme()
|
||||
@@ -659,10 +659,10 @@ func TestImportImportChannel(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
|
||||
// Mark the phase 2 permissions migration as completed.
|
||||
<-th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
|
||||
defer func() {
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
}()
|
||||
|
||||
scheme1 := th.SetupChannelScheme()
|
||||
@@ -1505,10 +1505,10 @@ func TestImportImportUser(t *testing.T) {
|
||||
// to the appropriate scheme-managed-role booleans.
|
||||
|
||||
// Mark the phase 2 permissions migration as completed.
|
||||
<-th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
|
||||
defer func() {
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
}()
|
||||
|
||||
teamSchemeData := &SchemeImportData{
|
||||
|
||||
@@ -18,8 +18,8 @@ func (a *App) LoadLicense() {
|
||||
a.SetLicense(nil)
|
||||
|
||||
licenseId := ""
|
||||
if result := <-a.Srv.Store.System().Get(); result.Err == nil {
|
||||
props := result.Data.(model.StringMap)
|
||||
props, err := a.Srv.Store.System().Get()
|
||||
if err == nil {
|
||||
licenseId = props[model.SYSTEM_ACTIVE_LICENSE_ID]
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ func (a *App) LoadLicense() {
|
||||
license, licenseBytes := utils.GetAndValidateLicenseFileFromDisk(*a.Config().ServiceSettings.LicenseFileLocation)
|
||||
|
||||
if license != nil {
|
||||
if _, err := a.SaveLicense(licenseBytes); err != nil {
|
||||
if _, err = a.SaveLicense(licenseBytes); err != nil {
|
||||
mlog.Info(fmt.Sprintf("Failed to save license key loaded from disk err=%v", err.Error()))
|
||||
} else {
|
||||
licenseId = license.Id
|
||||
@@ -84,9 +84,7 @@ func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError)
|
||||
sysVar := &model.System{}
|
||||
sysVar.Name = model.SYSTEM_ACTIVE_LICENSE_ID
|
||||
sysVar.Value = license.Id
|
||||
schan := a.Srv.Store.System().SaveOrUpdate(sysVar)
|
||||
|
||||
if result := <-schan; result.Err != nil {
|
||||
if err := a.Srv.Store.System().SaveOrUpdate(sysVar); err != nil {
|
||||
a.RemoveLicense()
|
||||
return nil, model.NewAppError("addLicense", "api.license.add_license.save_active.app_error", nil, "", http.StatusInternalServerError)
|
||||
}
|
||||
@@ -162,8 +160,8 @@ func (a *App) RemoveLicense() *model.AppError {
|
||||
sysVar.Name = model.SYSTEM_ACTIVE_LICENSE_ID
|
||||
sysVar.Value = ""
|
||||
|
||||
if result := <-a.Srv.Store.System().SaveOrUpdate(sysVar); result.Err != nil {
|
||||
return result.Err
|
||||
if err := a.Srv.Store.System().SaveOrUpdate(sysVar); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.SetLicense(nil)
|
||||
|
||||
@@ -19,7 +19,7 @@ const GUEST_ROLES_CREATION_MIGRATION_KEY = "GuestRolesCreationMigrationComplete"
|
||||
// This function migrates the default built in roles from code/config to the database.
|
||||
func (a *App) DoAdvancedPermissionsMigration() {
|
||||
// If the migration is already marked as completed, don't do it again.
|
||||
if result := <-a.Srv.Store.System().GetByName(ADVANCED_PERMISSIONS_MIGRATION_KEY); result.Err == nil {
|
||||
if _, err := a.Srv.Store.System().GetByName(ADVANCED_PERMISSIONS_MIGRATION_KEY); err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -74,16 +74,15 @@ func (a *App) DoAdvancedPermissionsMigration() {
|
||||
Value: "true",
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.System().Save(&system); result.Err != nil {
|
||||
mlog.Critical("Failed to mark advanced permissions migration as completed.", mlog.Err(result.Err))
|
||||
if err := a.Srv.Store.System().Save(&system); err != nil {
|
||||
mlog.Critical("Failed to mark advanced permissions migration as completed.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) SetPhase2PermissionsMigrationStatus(isComplete bool) error {
|
||||
if !isComplete {
|
||||
res := <-a.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
if res.Err != nil {
|
||||
return res.Err
|
||||
if _, err := a.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
a.Srv.phase2PermissionsMigrationComplete = isComplete
|
||||
@@ -92,7 +91,7 @@ func (a *App) SetPhase2PermissionsMigrationStatus(isComplete bool) error {
|
||||
|
||||
func (a *App) DoEmojisPermissionsMigration() {
|
||||
// If the migration is already marked as completed, don't do it again.
|
||||
if result := <-a.Srv.Store.System().GetByName(EMOJIS_PERMISSIONS_MIGRATION_KEY); result.Err == nil {
|
||||
if _, err := a.Srv.Store.System().GetByName(EMOJIS_PERMISSIONS_MIGRATION_KEY); err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -147,14 +146,14 @@ func (a *App) DoEmojisPermissionsMigration() {
|
||||
Value: "true",
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.System().Save(&system); result.Err != nil {
|
||||
mlog.Critical("Failed to mark emojis permissions migration as completed.", mlog.Err(result.Err))
|
||||
if err := a.Srv.Store.System().Save(&system); err != nil {
|
||||
mlog.Critical("Failed to mark emojis permissions migration as completed.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) DoGuestRolesCreationMigration() {
|
||||
// If the migration is already marked as completed, don't do it again.
|
||||
if result := <-a.Srv.Store.System().GetByName(GUEST_ROLES_CREATION_MIGRATION_KEY); result.Err == nil {
|
||||
if _, err := a.Srv.Store.System().GetByName(GUEST_ROLES_CREATION_MIGRATION_KEY); err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -235,8 +234,8 @@ func (a *App) DoGuestRolesCreationMigration() {
|
||||
Value: "true",
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.System().Save(&system); result.Err != nil {
|
||||
mlog.Critical("Failed to mark guest roles creation migration as completed.", mlog.Err(result.Err))
|
||||
if err := a.Srv.Store.System().Save(&system); err != nil {
|
||||
mlog.Critical("Failed to mark guest roles creation migration as completed.", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ func (a *App) ResetPermissionsSystem() *model.AppError {
|
||||
}
|
||||
|
||||
// Remove the "System" table entry that marks the advanced permissions migration as done.
|
||||
if result := <-a.Srv.Store.System().PermanentDeleteByName(ADVANCED_PERMISSIONS_MIGRATION_KEY); result.Err != nil {
|
||||
return result.Err
|
||||
if _, err := a.Srv.Store.System().PermanentDeleteByName(ADVANCED_PERMISSIONS_MIGRATION_KEY); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Now that the permissions system has been reset, re-run the migration to reinitialise it.
|
||||
|
||||
@@ -124,7 +124,7 @@ func applyPermissionsMap(roleName string, roleMap map[string]map[string]bool, mi
|
||||
}
|
||||
|
||||
func (a *App) doPermissionsMigration(key string, migrationMap permissionsMap) *model.AppError {
|
||||
if result := <-a.Srv.Store.System().GetByName(key); result.Err == nil {
|
||||
if _, err := a.Srv.Store.System().GetByName(key); err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -148,8 +148,8 @@ func (a *App) doPermissionsMigration(key string, migrationMap permissionsMap) *m
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.System().Save(&model.System{Name: key, Value: "true"}); result.Err != nil {
|
||||
return result.Err
|
||||
if err := a.Srv.Store.System().Save(&model.System{Name: key, Value: "true"}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -252,11 +252,11 @@ func TestImportPermissions_schemeDeletedOnRoleFailure(t *testing.T) {
|
||||
|
||||
func withMigrationMarkedComplete(th *TestHelper, f func()) {
|
||||
// Mark the migration as done.
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
<-th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv.Store.System().Save(&model.System{Name: model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2, Value: "true"})
|
||||
// Un-mark the migration at the end of the test.
|
||||
defer func() {
|
||||
<-th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
th.App.Srv.Store.System().PermanentDeleteByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2)
|
||||
}()
|
||||
f()
|
||||
}
|
||||
|
||||
@@ -158,8 +158,8 @@ func (a *App) IsPhase2MigrationCompleted() *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
if result := <-a.Srv.Store.System().GetByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2); result.Err != nil {
|
||||
return model.NewAppError("App.IsPhase2MigrationCompleted", "app.schemes.is_phase_2_migration_completed.not_completed.app_error", nil, result.Err.Error(), http.StatusNotImplemented)
|
||||
if _, err := a.Srv.Store.System().GetByName(model.MIGRATION_KEY_ADVANCED_PERMISSIONS_PHASE_2); err != nil {
|
||||
return model.NewAppError("App.IsPhase2MigrationCompleted", "app.schemes.is_phase_2_migration_completed.not_completed.app_error", nil, err.Error(), http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
a.Srv.phase2PermissionsMigrationComplete = true
|
||||
|
||||
@@ -33,93 +33,97 @@ const (
|
||||
)
|
||||
|
||||
func (s *Server) DoSecurityUpdateCheck() {
|
||||
if *s.Config().ServiceSettings.EnableSecurityFixAlert {
|
||||
if result := <-s.Store.System().Get(); result.Err == nil {
|
||||
props := result.Data.(model.StringMap)
|
||||
lastSecurityTime, _ := strconv.ParseInt(props[model.SYSTEM_LAST_SECURITY_TIME], 10, 0)
|
||||
currentTime := model.GetMillis()
|
||||
if !*s.Config().ServiceSettings.EnableSecurityFixAlert {
|
||||
return
|
||||
}
|
||||
|
||||
if (currentTime - lastSecurityTime) > SECURITY_UPDATE_PERIOD {
|
||||
mlog.Debug("Checking for security update from Mattermost")
|
||||
props, err := s.Store.System().Get()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
v := url.Values{}
|
||||
lastSecurityTime, _ := strconv.ParseInt(props[model.SYSTEM_LAST_SECURITY_TIME], 10, 0)
|
||||
currentTime := model.GetMillis()
|
||||
|
||||
v.Set(PROP_SECURITY_ID, s.diagnosticId)
|
||||
v.Set(PROP_SECURITY_BUILD, model.CurrentVersion+"."+model.BuildNumber)
|
||||
v.Set(PROP_SECURITY_ENTERPRISE_READY, model.BuildEnterpriseReady)
|
||||
v.Set(PROP_SECURITY_DATABASE, *s.Config().SqlSettings.DriverName)
|
||||
v.Set(PROP_SECURITY_OS, runtime.GOOS)
|
||||
if (currentTime - lastSecurityTime) > SECURITY_UPDATE_PERIOD {
|
||||
mlog.Debug("Checking for security update from Mattermost")
|
||||
|
||||
if len(props[model.SYSTEM_RAN_UNIT_TESTS]) > 0 {
|
||||
v.Set(PROP_SECURITY_UNIT_TESTS, "1")
|
||||
} else {
|
||||
v.Set(PROP_SECURITY_UNIT_TESTS, "0")
|
||||
}
|
||||
v := url.Values{}
|
||||
|
||||
systemSecurityLastTime := &model.System{Name: model.SYSTEM_LAST_SECURITY_TIME, Value: strconv.FormatInt(currentTime, 10)}
|
||||
if lastSecurityTime == 0 {
|
||||
<-s.Store.System().Save(systemSecurityLastTime)
|
||||
} else {
|
||||
<-s.Store.System().Update(systemSecurityLastTime)
|
||||
}
|
||||
v.Set(PROP_SECURITY_ID, s.diagnosticId)
|
||||
v.Set(PROP_SECURITY_BUILD, model.CurrentVersion+"."+model.BuildNumber)
|
||||
v.Set(PROP_SECURITY_ENTERPRISE_READY, model.BuildEnterpriseReady)
|
||||
v.Set(PROP_SECURITY_DATABASE, *s.Config().SqlSettings.DriverName)
|
||||
v.Set(PROP_SECURITY_OS, runtime.GOOS)
|
||||
|
||||
if ucr := <-s.Store.User().Count(model.UserCountOptions{
|
||||
IncludeDeleted: true,
|
||||
}); ucr.Err == nil {
|
||||
v.Set(PROP_SECURITY_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
|
||||
}
|
||||
if len(props[model.SYSTEM_RAN_UNIT_TESTS]) > 0 {
|
||||
v.Set(PROP_SECURITY_UNIT_TESTS, "1")
|
||||
} else {
|
||||
v.Set(PROP_SECURITY_UNIT_TESTS, "0")
|
||||
}
|
||||
|
||||
if ucr := <-s.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil {
|
||||
v.Set(PROP_SECURITY_ACTIVE_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
|
||||
}
|
||||
systemSecurityLastTime := &model.System{Name: model.SYSTEM_LAST_SECURITY_TIME, Value: strconv.FormatInt(currentTime, 10)}
|
||||
if lastSecurityTime == 0 {
|
||||
s.Store.System().Save(systemSecurityLastTime)
|
||||
} else {
|
||||
s.Store.System().Update(systemSecurityLastTime)
|
||||
}
|
||||
|
||||
if tcr := <-s.Store.Team().AnalyticsTeamCount(); tcr.Err == nil {
|
||||
v.Set(PROP_SECURITY_TEAM_COUNT, strconv.FormatInt(tcr.Data.(int64), 10))
|
||||
}
|
||||
if ucr := <-s.Store.User().Count(model.UserCountOptions{
|
||||
IncludeDeleted: true,
|
||||
}); ucr.Err == nil {
|
||||
v.Set(PROP_SECURITY_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
|
||||
}
|
||||
|
||||
res, err := http.Get(SECURITY_URL + "/security?" + v.Encode())
|
||||
if err != nil {
|
||||
mlog.Error("Failed to get security update information from Mattermost.")
|
||||
return
|
||||
}
|
||||
if ucr := <-s.Store.Status().GetTotalActiveUsersCount(); ucr.Err == nil {
|
||||
v.Set(PROP_SECURITY_ACTIVE_USER_COUNT, strconv.FormatInt(ucr.Data.(int64), 10))
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
if tcr := <-s.Store.Team().AnalyticsTeamCount(); tcr.Err == nil {
|
||||
v.Set(PROP_SECURITY_TEAM_COUNT, strconv.FormatInt(tcr.Data.(int64), 10))
|
||||
}
|
||||
|
||||
bulletins := model.SecurityBulletinsFromJson(res.Body)
|
||||
res, err := http.Get(SECURITY_URL + "/security?" + v.Encode())
|
||||
if err != nil {
|
||||
mlog.Error("Failed to get security update information from Mattermost.")
|
||||
return
|
||||
}
|
||||
|
||||
for _, bulletin := range bulletins {
|
||||
if bulletin.AppliesToVersion == model.CurrentVersion {
|
||||
if props["SecurityBulletin_"+bulletin.Id] == "" {
|
||||
results := <-s.Store.User().GetSystemAdminProfiles()
|
||||
if results.Err != nil {
|
||||
mlog.Error("Failed to get system admins for security update information from Mattermost.")
|
||||
return
|
||||
}
|
||||
users := results.Data.(map[string]*model.User)
|
||||
defer res.Body.Close()
|
||||
|
||||
resBody, err := http.Get(SECURITY_URL + "/bulletins/" + bulletin.Id)
|
||||
if err != nil {
|
||||
mlog.Error("Failed to get security bulletin details")
|
||||
return
|
||||
}
|
||||
bulletins := model.SecurityBulletinsFromJson(res.Body)
|
||||
|
||||
body, err := ioutil.ReadAll(resBody.Body)
|
||||
res.Body.Close()
|
||||
if err != nil || resBody.StatusCode != 200 {
|
||||
mlog.Error("Failed to read security bulletin details")
|
||||
return
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
mlog.Info(fmt.Sprintf("Sending security bulletin for %v to %v", bulletin.Id, user.Email))
|
||||
license := s.License()
|
||||
mailservice.SendMailUsingConfig(user.Email, utils.T("mattermost.bulletin.subject"), string(body), s.Config(), license != nil && *license.Features.Compliance)
|
||||
}
|
||||
|
||||
bulletinSeen := &model.System{Name: "SecurityBulletin_" + bulletin.Id, Value: bulletin.Id}
|
||||
<-s.Store.System().Save(bulletinSeen)
|
||||
}
|
||||
for _, bulletin := range bulletins {
|
||||
if bulletin.AppliesToVersion == model.CurrentVersion {
|
||||
if props["SecurityBulletin_"+bulletin.Id] == "" {
|
||||
results := <-s.Store.User().GetSystemAdminProfiles()
|
||||
if results.Err != nil {
|
||||
mlog.Error("Failed to get system admins for security update information from Mattermost.")
|
||||
return
|
||||
}
|
||||
users := results.Data.(map[string]*model.User)
|
||||
|
||||
resBody, err := http.Get(SECURITY_URL + "/bulletins/" + bulletin.Id)
|
||||
if err != nil {
|
||||
mlog.Error("Failed to get security bulletin details")
|
||||
return
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(resBody.Body)
|
||||
res.Body.Close()
|
||||
if err != nil || resBody.StatusCode != 200 {
|
||||
mlog.Error("Failed to read security bulletin details")
|
||||
return
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
mlog.Info(fmt.Sprintf("Sending security bulletin for %v to %v", bulletin.Id, user.Email))
|
||||
license := s.License()
|
||||
mailservice.SendMailUsingConfig(user.Email, utils.T("mattermost.bulletin.subject"), string(body), s.Config(), license != nil && *license.Features.Compliance)
|
||||
}
|
||||
|
||||
bulletinSeen := &model.System{Name: "SecurityBulletin_" + bulletin.Id, Value: bulletin.Id}
|
||||
s.Store.System().Save(bulletinSeen)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user