collavre_slack 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a8e800e1e2f729af9f99e0ebedc8e070723ba61f194ee9df766fcdfdd27c933
4
- data.tar.gz: 2737d507f261c19b3446afd84f8747d21cb849fcddfa5d139b2dbd9a9a7f96ad
3
+ metadata.gz: 9f8c6e3a4ad1e73641c6b9318e37714534c8e07b0a8d967c457f4ca1747eaa8e
4
+ data.tar.gz: '09e4084c8402be38a3429342d1b0988719338c584fee5002cef81b2462c3d7f4'
5
5
  SHA512:
6
- metadata.gz: c66ed359c01fc4d3c8f95badd2a9b692c01369187da548f5c9620fde05c7391c8e9c9011b8ba5f98f5f3bcb6925d97b2491992a38258a85b1a6999f330180bb0
7
- data.tar.gz: a86dad280226ab1c787e9c959b134fa4b1dde7245726a748620a396058171a3c21d2b469034c2bd2444fa9fbfc493d37b9980bf606a0f6ac2af6fad776426265
6
+ metadata.gz: db89b0c760d4a20219b0795aed1e127b230393fe8c2855556d812ce9ff7f6694725399815d962bbc872c9769cb136641f2b2288d58e09a74a05fc718211e7728
7
+ data.tar.gz: 23c172e7f68e4981d1c64ccb02a71418dc437ff91c2f4d218870dcde838e9d58e76f1472cca9a7564a57610f3a6f08d286747c1add643438686145a6ebbb1316
@@ -2,11 +2,10 @@ module CollavreSlack
2
2
  module Creatives
3
3
  class SlackIntegrationsController < ApplicationController
4
4
  before_action :set_creative
5
+ before_action :set_origin
5
6
 
6
7
  def index
7
- # Always use origin creative for Slack links (chat messages are on origin)
8
- target_creative = @creative.effective_origin
9
- @links = SlackChannelLink.where(creative: target_creative)
8
+ @links = SlackChannelLink.where(creative: @origin)
10
9
  respond_to do |format|
11
10
  format.json do
12
11
  slack_account = Current.user ? SlackAccount.find_by(user: Current.user) : nil
@@ -37,7 +36,7 @@ module CollavreSlack
37
36
 
38
37
  # Find the user's Slack account
39
38
  slack_account = if params[:slack_account_id].present?
40
- SlackAccount.find(params[:slack_account_id])
39
+ SlackAccount.find_by!(id: params[:slack_account_id], user: Current.user)
41
40
  else
42
41
  SlackAccount.find_by(user: Current.user)
43
42
  end
@@ -47,11 +46,8 @@ module CollavreSlack
47
46
  return
48
47
  end
49
48
 
50
- # Always link to origin creative (chat messages are on origin)
51
- target_creative = @creative.effective_origin
52
-
53
49
  service = SlackIntegrationService.new(user: Current.user, slack_account: slack_account)
54
- link = service.link_channel(creative: target_creative, channel_id: params[:channel_id], channel_name: params[:channel_name])
50
+ link = service.link_channel(creative: @origin, channel_id: params[:channel_id], channel_name: params[:channel_name])
55
51
 
56
52
  if link.persisted?
57
53
  render json: { success: true, link: { id: link.id, channel_id: link.channel_id, channel_name: link.channel_name } }, status: :created
@@ -60,10 +56,8 @@ module CollavreSlack
60
56
  end
61
57
  end
62
58
 
63
- # Lightweight endpoint for badge display — returns only existing links, no Slack API calls
64
59
  def badge
65
- target_creative = @creative.effective_origin
66
- links = SlackChannelLink.where(creative: target_creative)
60
+ links = SlackChannelLink.where(creative: @origin)
67
61
  render json: {
68
62
  links: links.map { |link|
69
63
  { channel_name: link.channel_name }
@@ -73,9 +67,7 @@ module CollavreSlack
73
67
 
74
68
  def destroy
75
69
  link = SlackChannelLink.find(params[:id])
76
- # Check against origin creative
77
- target_creative = @creative.effective_origin
78
- unless link.creative_id == target_creative.id
70
+ unless link.creative_id == @origin.id
79
71
  render json: { success: false, error: I18n.t("collavre_slack.errors.not_found") }, status: :not_found
80
72
  return
81
73
  end
@@ -95,6 +87,10 @@ module CollavreSlack
95
87
  @creative = Collavre::Creative.find(params[:creative_id])
96
88
  end
97
89
 
90
+ def set_origin
91
+ @origin = @creative.effective_origin
92
+ end
93
+
98
94
  def fetch_channels(slack_account)
99
95
  client = SlackClient.new(access_token: slack_account.access_token)
100
96
  client.list_all_channels.map do |channel|
@@ -65,7 +65,7 @@ module CollavreSlack
65
65
 
66
66
  if account.save
67
67
  # Render HTML that closes the popup and notifies the parent window
68
- render html: close_popup_html.html_safe, layout: false
68
+ render template: "collavre_slack/slack_auth/callback_success", layout: false
69
69
  else
70
70
  Rails.logger.error("[SlackAuth] Failed to save account: #{account.errors.full_messages.join(', ')}")
71
71
  render json: { error: I18n.t("collavre_slack.errors.save_failed", errors: account.errors.full_messages.join(", ")) }, status: :unprocessable_entity
@@ -81,25 +81,5 @@ module CollavreSlack
81
81
  def message_verifier
82
82
  @message_verifier ||= Rails.application.message_verifier("slack_oauth")
83
83
  end
84
-
85
- def close_popup_html
86
- title = I18n.t("collavre_slack.views.auth.success_title")
87
- message = I18n.t("collavre_slack.views.auth.success_message")
88
- <<~HTML
89
- <!DOCTYPE html>
90
- <html>
91
- <head><title>#{title}</title></head>
92
- <body>
93
- <p>#{message}</p>
94
- <script>
95
- if (window.opener) {
96
- window.opener.postMessage({ type: 'slack-auth-success' }, '*');
97
- }
98
- window.close();
99
- </script>
100
- </body>
101
- </html>
102
- HTML
103
- end
104
84
  end
105
85
  end
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head><title><%= t("collavre_slack.views.auth.success_title") %></title></head>
4
+ <body>
5
+ <p><%= t("collavre_slack.views.auth.success_message") %></p>
6
+ <script>
7
+ if (window.opener) {
8
+ window.opener.postMessage({ type: 'slack-auth-success' }, window.location.origin);
9
+ }
10
+ window.close();
11
+ </script>
12
+ </body>
13
+ </html>
@@ -1,3 +1,3 @@
1
1
  module CollavreSlack
2
- VERSION = "0.2.4"
2
+ VERSION = "0.2.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: collavre_slack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Collavre
@@ -110,6 +110,7 @@ files:
110
110
  - app/services/collavre_slack/slack_message_dispatcher.rb
111
111
  - app/views/collavre_slack/creatives/slack_integrations/index.html.erb
112
112
  - app/views/collavre_slack/integrations/_modal.html.erb
113
+ - app/views/collavre_slack/slack_auth/callback_success.html.erb
113
114
  - config/initializers/collavre_slack.rb
114
115
  - config/locales/en.yml
115
116
  - config/locales/ko.yml