Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"drupal/seckit": "^2.0",
"drupal/security_review": "1.x-dev",
"drupal/shield": "^1.2",
"drupal/slack_invite": "^2.0",
"drupal/stage_file_proxy": "^1.0@RC",
"drupal/token": "^1.5",
"drupal/upgrade_status": "^3.0@beta",
Expand Down
50 changes: 3 additions & 47 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
token: ""
hostname: ""
twostep:
enabled: FALSE
channel: ""
message: "!email has requested an invitation to the Slack team. Click the following link to approve: !url"
6 changes: 6 additions & 0 deletions docroot/modules/custom/slack_invite/slack_invite.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Slack Invite
type: module
description: 'Invite your users to your slack team'
package: Custom
core_version_requirement: ^9 || ^10 || ^11

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
slack_invite.settingss:
title: 'Slack Invite'
parent: system.admin_config_services
description: 'Slack Invite Settings'
route_name: slack_invite.settings
42 changes: 42 additions & 0 deletions docroot/modules/custom/slack_invite/slack_invite.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* @file
* Primarily Drupal hooks and global API functions to manipulate slack invite.
*
* This is the main module file for Slack Invite.
*/


define('SLACK_INVITE_ALREADY_IN_TEAM', 'already_in_team');
define('SLACK_INVITE_SENT_RECENTLY', 'sent_recently');
define('SLACK_INVITE_ALREADY_INVITED', 'already_invited');

/**
* Sends slack invite to email address.
*/
function _slack_invite_send_invite($email) {
$team_hostname = variable_get('slack_invite_hostname', '');
$api_url = "https://{$team_hostname}.slack.com/api/users.admin.invite?t=" . time();

$data = [
'_attempts' => 1,
'email' => $email,
'set_active' => 'true',
'token' => variable_get('slack_invite_token', ''),
];

$data['channels'] = variable_get('slack_invite_channels', '');
if (empty($data['channels'])) {
unset($data['channels']);
}

$data = drupal_http_build_query($data);
$options = [
'method' => 'POST',
'headers' => ['Content-Type' => 'application/x-www-form-urlencoded'],
'data' => $data,
];

return drupal_http_request("{$api_url}", $options);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
administer slack invite:
title: 'Administer Slack Invite Settings.'
description: 'Administer the Slack Invite Settings.'

approve slack invite:
title: 'Approve Slack Invites.'
description: 'Approve two-step Slack invitations.'
15 changes: 15 additions & 0 deletions docroot/modules/custom/slack_invite/slack_invite.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
slack_invite.settings:
path: '/admin/config/services/slack-invite'
defaults:
_form: 'Drupal\slack_invite\Form\SlackInviteSettingsForm'
_title: 'Slack Invite Settings'
requirements:
_permission: 'administer slack invite'

slack_invite.twostep:
path: '/slack_invite/{email}/{token}'
defaults:
_form: 'Drupal\slack_invite\Form\SlackInviteTwoStepApproveForm'
_title: 'Approve Slack invitation'
requirements:
_custom_access: 'Drupal\slack_invite\Form\SlackInviteTwoStepApproveForm::access'
3 changes: 3 additions & 0 deletions docroot/modules/custom/slack_invite/slack_invite.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
services:
slack_invite:
class: Drupal\slack_invite\SlackInvite
68 changes: 68 additions & 0 deletions docroot/modules/custom/slack_invite/src/Form/SlackInviteForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* @file
* Contains \Drupal\slack_invite\Form\SlackInviteForm.
*/

namespace Drupal\slack_invite\Form;

use Drupal\Core\Http\Client;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Exception;
use Drupal\Core\Url;

/**
* Builds the search form for the search block.
*/
class SlackInviteForm extends FormBase {

/**
* {@inheritdoc}
*/
public function getFormID() {
return 'slack_invite_form';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('slack_invite.settings');

$form['#action'] = Url::fromRoute('<current>', ['query' => $this->getDestinationArray(), 'external' => FALSE])->toString();
$form['slack_email'] = [
'#type' => 'textfield',
'#title' => $this->t('Email'),
'#description' => $this->t('Enter email address for slack invite'),
'#required' => TRUE,
];

$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Send')
];
return $form;
}

/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$email = $form_state->getValue('slack_email');
if (!\Drupal::service('email.validator')->isValid($email)) {
$form_state->setErrorByName('slack_email', $this->t('Enter email address in valid format (ex. example@example.com)'));
}
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$slack_invite = \Drupal::service('slack_invite');
$slack_invite->send($form_state->getValue('slack_email'));
}
}
Loading