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 +4 -4
- data/app/controllers/collavre_slack/creatives/slack_integrations_controller.rb +10 -14
- data/app/controllers/collavre_slack/slack_auth_controller.rb +1 -21
- data/app/views/collavre_slack/slack_auth/callback_success.html.erb +13 -0
- data/lib/collavre_slack/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9f8c6e3a4ad1e73641c6b9318e37714534c8e07b0a8d967c457f4ca1747eaa8e
|
|
4
|
+
data.tar.gz: '09e4084c8402be38a3429342d1b0988719338c584fee5002cef81b2462c3d7f4'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
-
|
|
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.
|
|
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:
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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>
|
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
|
+
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
|