Class: CollavreNotion::Creatives::NotionIntegrationsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- CollavreNotion::Creatives::NotionIntegrationsController
- Includes:
- Collavre::IntegrationPermission, Collavre::IntegrationSetup
- Defined in:
- app/controllers/collavre_notion/creatives/notion_integrations_controller.rb
Instance Method Summary collapse
Instance Method Details
#destroy ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/collavre_notion/creatives/notion_integrations_controller.rb', line 82 def destroy unless @creative.(Current.user, :write) render json: { error: }, status: :forbidden return end account = Current.user.notion_account unless account render json: { error: "not_connected" }, status: :unprocessable_entity return end page_id = params[:page_id] if page_id # Remove specific page link link = linked_page_links(account).find_by(page_id: page_id) unless link render json: { error: "not_found" }, status: :not_found return end link.destroy! else # Remove all page links for this creative linked_page_links(account).destroy_all end links = linked_page_links(account) render json: { success: true, linked_pages: links.map do |link| { page_id: link.page_id, page_title: link.page_title, page_url: link.page_url, last_synced_at: link.last_synced_at } end } end |
#show ⇒ Object
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 |
# File 'app/controllers/collavre_notion/creatives/notion_integrations_controller.rb', line 11 def show account = Current.user.notion_account links = linked_page_links(account) Rails.logger.info("Notion Integration: Showing status for user #{Current.user.id}, connected: #{account.present?}") render json: { connected: account.present?, creative_title: helpers.(@creative.effective_origin.description.to_s).strip.presence || "Untitled Creative", account: account && { workspace_name: account.workspace_name, workspace_id: account.workspace_id, bot_id: account.bot_id }, linked_pages: links.map do |link| { page_id: link.page_id, page_title: link.page_title, page_url: link.page_url, last_synced_at: link.last_synced_at } end, available_pages: account.present? ? fetch_available_pages(account) : [] } end |
#update ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/collavre_notion/creatives/notion_integrations_controller.rb', line 37 def update account = Current.user.notion_account unless account render json: { error: "not_connected" }, status: :unprocessable_entity return end Rails.logger.info("Notion Integration Update: Full params = #{params.to_unsafe_h}") integration_attributes = integration_params Rails.logger.info("Notion Integration Update: integration_params = #{integration_attributes}") request_action = request.request_parameters[:action] action = integration_attributes[:action] if action.blank? || action.to_s == action_name action = request_action.presence end parent_page_id = integration_attributes[:parent_page_id] Rails.logger.info("Notion Integration Update: action=#{action}, parent_page_id=#{parent_page_id}") begin case action when "export" # Export creative to Notion CollavreNotion::NotionExportJob.perform_later(@creative, account, parent_page_id) render json: { success: true, message: "Export started" } when "sync" # Sync existing page link = linked_page_links(account).first if link CollavreNotion::NotionSyncJob.perform_later(@creative, account, link.page_id) render json: { success: true, message: "Sync started" } else render json: { error: "no_linked_page" }, status: :unprocessable_entity end else render json: { error: "invalid_action" }, status: :unprocessable_entity end rescue StandardError => e Rails.logger.error("Notion integration error: #{e.}") render json: { error: "operation_failed", message: e. }, status: :internal_server_error end end |