Exemple #1
0
func UpdateAppSettings(cmd *m.UpdateAppSettingsCmd) error {
	return inTransaction2(func(sess *session) error {
		var app m.AppSettings

		exists, err := sess.Where("org_id=? and app_id=?", cmd.OrgId, cmd.AppId).Get(&app)
		sess.UseBool("enabled")
		sess.UseBool("pinned")
		if !exists {
			app = m.AppSettings{
				AppId:          cmd.AppId,
				OrgId:          cmd.OrgId,
				Enabled:        cmd.Enabled,
				Pinned:         cmd.Pinned,
				JsonData:       cmd.JsonData,
				SecureJsonData: cmd.GetEncryptedJsonData(),
				Created:        time.Now(),
				Updated:        time.Now(),
			}
			_, err = sess.Insert(&app)
			return err
		} else {
			for key, data := range cmd.SecureJsonData {
				app.SecureJsonData[key] = util.Encrypt([]byte(data), setting.SecretKey)
			}
			app.SecureJsonData = cmd.GetEncryptedJsonData()
			app.Updated = time.Now()
			app.Enabled = cmd.Enabled
			app.JsonData = cmd.JsonData
			app.Pinned = cmd.Pinned
			_, err = sess.Id(app.Id).Update(&app)
			return err
		}
	})
}
Exemple #2
0
func UpdateAppSettings(cmd *m.UpdateAppSettingsCmd) error {
	return inTransaction2(func(sess *session) error {
		var app m.AppSettings

		exists, err := sess.Where("org_id=? and app_id=?", cmd.OrgId, cmd.AppId).Get(&app)
		sess.UseBool("enabled")
		sess.UseBool("pinned")
		if !exists {
			app = m.AppSettings{
				AppId:    cmd.AppId,
				OrgId:    cmd.OrgId,
				Enabled:  cmd.Enabled,
				Pinned:   cmd.Pinned,
				JsonData: cmd.JsonData,
				Created:  time.Now(),
				Updated:  time.Now(),
			}
			_, err = sess.Insert(&app)
			return err
		} else {
			app.Updated = time.Now()
			app.Enabled = cmd.Enabled
			app.JsonData = cmd.JsonData
			app.Pinned = cmd.Pinned
			_, err = sess.Id(app.Id).Update(&app)
			return err
		}
	})
}