|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class StripeSlackSiteConfigExtension |
|
6
|
|
|
* |
|
7
|
|
|
* @property SiteConfig|StripeSlackSiteConfigExtension $owner |
|
8
|
|
|
* @property string $SlackURL |
|
9
|
|
|
* @property string $SlackClientID |
|
10
|
|
|
* @property string $SlackClientSecret |
|
11
|
|
|
* @property string $SlackChannel |
|
12
|
|
|
* @property string $SlackToken |
|
13
|
|
|
* @property boolean $ClearSecrets |
|
14
|
|
|
* @property int $SlackBackURLID |
|
15
|
|
|
* @property int $SlackErrorBackURLID |
|
16
|
|
|
* @method SiteTree SlackBackURL() |
|
17
|
|
|
* @method SiteTree SlackErrorBackURL() |
|
18
|
|
|
*/ |
|
19
|
|
|
class StripeSlackSiteConfigExtension extends DataExtension |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
private static $db = [ |
|
22
|
|
|
'SlackURL' => 'Varchar(255)', |
|
23
|
|
|
'SlackClientID' => 'Varchar(255)', |
|
24
|
|
|
'SlackClientSecret' => 'Varchar(255)', |
|
25
|
|
|
'SlackChannel' => 'Varchar(255)', |
|
26
|
|
|
'SlackToken' => 'Varchar(255)', |
|
27
|
|
|
// This is here to support the IDE's |
|
28
|
|
|
'ClearSecrets' => 'Boolean(false)' |
|
29
|
|
|
]; |
|
30
|
|
|
|
|
31
|
|
|
private static $has_one = [ |
|
|
|
|
|
|
32
|
|
|
'SlackBackURL' => SiteTree::class, |
|
|
|
|
|
|
33
|
|
|
'SlackErrorBackURL' => SiteTree::class |
|
34
|
|
|
]; |
|
35
|
|
|
|
|
36
|
|
|
private static $helptexts = [ |
|
37
|
|
|
'Link' => 'To activate your StripeSlack, Please have an admin activate StripeSlack by clicking on this link.', |
|
38
|
|
|
'ClearSecrets' => 'Checking this checkbox will clear out the Client Secret and (invisible in the CMS) Client Token. In case your admin left the group, or you want a new admin to sent the invite', |
|
39
|
|
|
'Channel' => 'You can get the ID by right clicking on your channel and select "copy link". Open the copied link in a browser and copy the part after "messages/" in to this field', |
|
40
|
|
|
'URLHelp' => 'Include the "https://" part', |
|
41
|
|
|
'Extended' => '<p><a href="https://github.com/Firesphere/silverstripe-stripeslack/blob/master/readme.md">Extensive instructions can be found on GitHub</a></p>' |
|
42
|
|
|
]; |
|
43
|
|
|
|
|
44
|
|
|
public function updateFieldLabels(&$labels) |
|
45
|
|
|
{ |
|
46
|
|
|
$labels['SlackURL'] = _t('StripeSlackSiteConfigExtension.SlackURL', 'URL Of the Slack channel'); |
|
|
|
|
|
|
47
|
|
|
$labels['SlackClientID'] = _t('StripeSlackSiteConfigExtension.SlackClientID', 'Client ID for your Slack App'); |
|
48
|
|
|
$labels['SlackClientSecret'] = _t( |
|
49
|
|
|
'StripeSlackSiteConfigExtension.SlackClientSecret', |
|
50
|
|
|
'Client Secret for your Slack App' |
|
51
|
|
|
); |
|
52
|
|
|
$labels['SlackChannel'] = _t('StripeSlackSiteConfigExtension.SlackChannel', 'The ID of your channel'); |
|
53
|
|
|
$labels['ClearSecrets'] = _t('StripeSlackSiteConfigExtension.ClearSecrets', 'Clear Secrets and Tokens'); |
|
54
|
|
|
$labels['SlackBackURL'] = _t( |
|
55
|
|
|
'StripeSlackSiteConfigExtension.SlackBackURL', |
|
56
|
|
|
'URL to redirect when request is successful (leave empty if you want use the Stripe Slack Page)' |
|
57
|
|
|
); |
|
58
|
|
|
$labels['SlackErrorBackURL'] = _t( |
|
59
|
|
|
'StripeSlackSiteConfigExtension.SlackErrorBackURL', |
|
60
|
|
|
'URL to redirect when request is unsuccessful (leave empty if you want to use the Stripe Slack Page)' |
|
61
|
|
|
); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function updateCMSFields(FieldList $fields) |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
$fields->removeByName(['SlackToken']); |
|
67
|
|
|
$fields->addFieldsToTab('Root.Slack', [ |
|
68
|
|
|
$url = TextField::create('SlackURL', $this->owner->fieldLabel('SlackURL')), |
|
|
|
|
|
|
69
|
|
|
$channel = TextField::create('SlackChannel', $this->owner->fieldLabel('SlackChannel')), |
|
70
|
|
|
TextField::create('SlackClientID', $this->owner->fieldLabel('SlackClientID')), |
|
71
|
|
|
PasswordField::create('SlackClientSecret', $this->owner->fieldLabel('SlackClientSecret')), |
|
|
|
|
|
|
72
|
|
|
TreeDropdownField::create('SlackBackURLID', $this->owner->fieldLabel('SlackBackURL'), 'SiteTree'), |
|
|
|
|
|
|
73
|
|
|
TreeDropdownField::create('SlackErrorBackURLID', $this->owner->fieldLabel('SlackErrorBackURL'), 'SiteTree'), |
|
74
|
|
|
]); |
|
75
|
|
|
if ( |
|
76
|
|
|
$this->owner->SlackURL && |
|
77
|
|
|
$this->owner->SlackClientID && |
|
78
|
|
|
$this->owner->SlackClientSecret && |
|
79
|
|
|
!$this->owner->SlackToken |
|
80
|
|
|
) { |
|
81
|
|
|
$domain = Director::absoluteURL('/SlackAuthorization/'); |
|
82
|
|
|
$text = LiteralField::create( |
|
|
|
|
|
|
83
|
|
|
'link', |
|
84
|
|
|
'<p><a href="' . $this->owner->SlackURL . '/oauth/authorize?client_id=' . $this->owner->SlackClientID . '&scope=client&redirect_uri=' . $domain . '">' . |
|
85
|
|
|
static::$helptexts['Link'] . |
|
|
|
|
|
|
86
|
|
|
'</a></p>' |
|
87
|
|
|
); |
|
88
|
|
|
$fields->addFieldToTab('Root.Slack', $text); |
|
89
|
|
|
} else { |
|
90
|
|
|
$fields->addFieldsToTab( |
|
91
|
|
|
'Root.Slack', |
|
92
|
|
|
[ |
|
93
|
|
|
$secretField = CheckboxField::create('ClearSecrets', $this->owner->fieldLabel('ClearSecrets')), |
|
|
|
|
|
|
94
|
|
|
ReadonlyField::create('Users on Slack', SlackStatusController::create()->usercount(new SS_HTTPRequest('GET', '/SlackStatus/usercount'))) |
|
|
|
|
|
|
95
|
|
|
] |
|
96
|
|
|
); |
|
97
|
|
|
$secretField->setDescription(static::$helptexts['ClearSecrets']); |
|
98
|
|
|
} |
|
99
|
|
|
$channel->setDescription(static::$helptexts['Channel']); |
|
100
|
|
|
$url->setDescription(static::$helptexts['URLHelp']); |
|
101
|
|
|
|
|
102
|
|
|
$fields->addFieldToTab('Root.Slack', LiteralField::create('instructions', static::$helptexts['Extended'])); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Clear out the secrets if the checkbox is checked |
|
107
|
|
|
*/ |
|
108
|
|
|
public function onBeforeWrite() |
|
109
|
|
|
{ |
|
110
|
|
|
parent::onBeforeWrite(); |
|
111
|
|
|
if ($this->owner->ClearSecrets) { |
|
112
|
|
|
$this->owner->SlackClientSecret = ''; |
|
113
|
|
|
$this->owner->SlackToken = ''; |
|
114
|
|
|
} |
|
115
|
|
|
// Always set back to false so the checkbox won't stay ticked |
|
116
|
|
|
$this->owner->ClearSecrets = false; |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths