Sha256: c82f8e3f9fa2e3992054e3c14e8945af4b214e9a251572d32b66543b3b8b26dc

Contents?: true

Size: 1.97 KB

Versions: 8

Compression:

Stored size: 1.97 KB

Contents

module Locomotive
  module API
    module Resources

      class CurrentSiteResource < Grape::API

        resource :current_site do
          entity_klass = Entities::SiteEntity

          before do
            authenticate_locomotive_account!
            require_site!
          end

          helpers do

            def service
              @service ||= Locomotive::SiteService.new(current_account)
            end

          end

          desc 'Show current_site'
          get do
            authorize current_site, :show?

            present current_site, with: entity_klass
          end

          desc 'Update current site'
          params do
            requires :site, type: Hash do
              optional :name
              optional :handle
              optional :seo_title
              optional :meta_keywords
              optional :meta_description
              optional :robots_txt
              optional :locales, type: Array
              optional :domains, type: Array
              optional :url_redirections, type: Array
              optional :timezone
              optional :picture
              optional :metafields_schema
              optional :metafields
              optional :metafields_ui
              optional :asset_host
              optional :sections_content
              optional :routes
            end
          end
          put do
            authorize current_site, :update?

            current_site_form = Forms::SiteForm.new(permitted_params_from_policy(current_site, :site, [:picture], [:metafields_ui, :metafields_schema, :metafields, :sections_content, :routes]))
            service.update!(current_site, current_site_form.serializable_hash)

            present current_site, with: entity_klass
          end


          desc "Delete current site"
          delete do
            authorize current_site, :destroy?

            current_site.destroy

            present current_site, with: entity_klass
          end

        end
      end

    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
locomotivecms-4.0.3 app/api/locomotive/api/resources/current_site_resource.rb
locomotivecms-4.0.2 app/api/locomotive/api/resources/current_site_resource.rb
locomotivecms-4.0.1 app/api/locomotive/api/resources/current_site_resource.rb
locomotivecms-4.0.0 app/api/locomotive/api/resources/current_site_resource.rb
locomotivecms-4.0.0.rc0 app/api/locomotive/api/resources/current_site_resource.rb
locomotivecms-4.0.0.alpha3 app/api/locomotive/api/resources/current_site_resource.rb
locomotivecms-4.0.0.alpha2 app/api/locomotive/api/resources/current_site_resource.rb
locomotivecms-4.0.0.alpha1 app/api/locomotive/api/resources/current_site_resource.rb