settings.rb 888 字节
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
module API
  class Settings < Grape::API
    before { authenticate! }
    before { authorize_admin_project }

    helpers do
      def current_settings
        @current_setting ||= ApplicationSetting.current
      end
    end

    # Get current applicaiton settings
    #
    # Example Request:
    #   GET /application/settings
    get "application/settings" do
      present current_settings, with: Entities::ApplicationSetting
    end

    # Modify applicaiton settings
    #
    # Example Request:
    #   PUT /application/settings
    put "application/settings" do
      attributes = current_settings.attributes.keys - ["id"]
      attrs = attributes_for_keys(attributes)

      if current_settings.update_attributes(attrs)
        present current_settings, with: Entities::ApplicationSetting
      else
        render_validation_error!(current_settings)
      end
    end
  end
end