ui/setting.go
func (h *Handler) UpdateSettings(tkn string, items map[string]string) error {
	logger := h.logger.Add("method", "UpdateSettings")

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return ErrAccessDenied
	}

	err := h.db.InTransaction(func(tx *reform.TX) error {
		for k, v := range items {
			if err := h.validateSetting(logger, k, v); err != nil {
				logger.Add("key", k, "value", v).Error(err.Error())
				return err
			}
		}

		for k, v := range items {
			logger = logger.Add("key", k, "value", v)

			var settingFromDB data.Setting

			// gets setting from database
			err := tx.FindByPrimaryKeyTo(&settingFromDB, k)
			if err != nil {
				logger.Error(err.Error())
				return ErrInternal
			}

			// if settings.permissions != data.ReadWrite
			// then setting ignored
			if settingFromDB.Permissions != data.ReadWrite {
				continue
			}

			setting := settingFromDB
			setting.Value = v

			err = tx.Update(&setting)
			if err != nil {
				logger.Error(err.Error())
				return ErrInternal
			}
		}
		return nil
	})

	if err != nil {
		return h.catchError(logger, err)
	}
	return nil
}
func (h *Handler) UpdateSettings(tkn string, items map[string]string) error {
	logger := h.logger.Add("method", "UpdateSettings")

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return ErrAccessDenied
	}

	err := h.db.InTransaction(func(tx *reform.TX) error {
		for k, v := range items {
			if err := h.validateSetting(logger, k, v); err != nil {
				logger.Add("key", k, "value", v).Error(err.Error())
				return err
			}
		}

		for k, v := range items {
			logger = logger.Add("key", k, "value", v)

			var settingFromDB data.Setting

			// gets setting from database
			err := tx.FindByPrimaryKeyTo(&settingFromDB, k)
			if err != nil {
				logger.Error(err.Error())
				return ErrInternal
			}

			// if settings.permissions != data.ReadWrite
			// then setting ignored
			if settingFromDB.Permissions != data.ReadWrite {
				continue
			}

			setting := settingFromDB
			setting.Value = v

			err = tx.Update(&setting)
			if err != nil {
				logger.Error(err.Error())
				return ErrInternal
			}
		}
		return nil
	})

	if err != nil {
		return h.catchError(logger, err)
	}
	return nil
}
// UpdateSettings updates settings.