예제 #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
		}
	})
}
예제 #2
0
func UpdateAppSettings(c *middleware.Context, cmd m.UpdateAppSettingsCmd) Response {
	appId := c.Params(":appId")

	cmd.OrgId = c.OrgId
	cmd.AppId = appId

	if _, ok := plugins.Apps[cmd.AppId]; !ok {
		return ApiError(404, "App type not installed.", nil)
	}

	err := bus.Dispatch(&cmd)
	if err != nil {
		return ApiError(500, "Failed to update App Plugin", err)
	}

	return ApiSuccess("App updated")
}