Exemplo n.º 1
0
 public function testChannelUpdate()
 {
     // pre test
     Seat::set('slack_token', getenv('slack_token'));
     // test
     // get list of channels
     $channels = array_merge($this->slackApi->channels(false), $this->slackApi->channels(true));
     // store all channels in an array of object
     $artifacts = [];
     foreach ($channels as $c) {
         $artifacts[] = new SlackChannel(['id' => $c['id'], 'name' => $c['name']]);
     }
     // call slack:update:channels command
     $job = new SlackChannelsUpdate();
     $job->handle();
     // fetch in database channels
     $inDatabase = SlackChannel::all(['id', 'name']);
     // convert to an array of "new object"
     $result = [];
     foreach ($inDatabase as $object) {
         $result[] = new SlackChannel(['id' => $object->id, 'name' => $object->name]);
     }
     // compare both array
     $this->assertEquals($artifacts, $result);
 }
Exemplo n.º 2
0
 public function getRelations()
 {
     $channelPublic = SlackChannelPublic::all();
     $channelUsers = SlackChannelUser::all();
     $channelRoles = SlackChannelRole::all();
     $channelCorporations = SlackChannelCorporation::all();
     $channelAlliances = SlackChannelAlliance::all();
     $users = User::all();
     $roles = Role::all();
     $corporations = CorporationSheet::all();
     $alliances = AllianceList::all();
     $channels = SlackChannel::all();
     return view('slackbot::list', compact('channelPublic', 'channelUsers', 'channelRoles', 'channelCorporations', 'channelAlliances', 'users', 'roles', 'corporations', 'alliances', 'channels'));
 }
Exemplo n.º 3
0
 public function handle()
 {
     $token = Seat::get('slack_token');
     if ($token == null) {
         throw new SlackSettingException("missing slack_token in settings");
     }
     // init Slack Api using token
     $api = new SlackApi($token);
     // make a call in order to fetch both public and private channels
     $channels = array_merge($api->channels(false), $api->channels(true));
     $slackChannelIds = [];
     // iterate over each slack channel and create or update information from SeAT
     foreach ($channels as $channel) {
         // init channels ids array which will be used later in order to remove outdate channels
         $slackChannelIds[] = $channel['id'];
         // init flags to default value
         $isGroup = true;
         $isGeneral = false;
         // try to get channel object from SeAT
         $slackChannel = SlackChannel::find($channel['id']);
         // Determine if this is a group (private channel) or a channel
         if (substr($channel['id'], 0, 1) === 'C') {
             $isGroup = false;
         }
         if ($isGroup == false) {
             $isGeneral = (bool) $channel['is_general'];
         }
         // create the channel if it doesn't exist
         if ($slackChannel == null) {
             SlackChannel::create(['id' => $channel['id'], 'name' => $channel['name'], 'is_group' => $isGroup, 'is_general' => $isGeneral]);
             continue;
         }
         // update the channel if it is already known by SeAT
         $slackChannel->update(['name' => $channel['name'], 'is_general' => $isGeneral]);
     }
     // get all known channels from SeAT
     SlackChannel::whereNotIn('id', $slackChannelIds)->delete();
     /*
     // iterate over each of them and check if they are still valid
     // if not, we will remove them from the database since they are no longer usable
     foreach ($seatChannels as $channel) {
         if (in_array($channel->id, $slackChannelIds) == false) {
             $channel->delete();
         }
     }
     */
 }
Exemplo n.º 4
0
 private function restoreGroup($groupId)
 {
     // load token and team uri from settings
     $token = Seat::get('slack_token');
     if ($token == null) {
         throw new SlackSettingException("missing slack_token in settings");
     }
     $slackApi = new SlackApi($token);
     $apiGroup = $slackApi->info($groupId, true);
     SlackChannel::create(['id' => $apiGroup['id'], 'name' => $apiGroup['name'], 'is_group' => true]);
 }
Exemplo n.º 5
0
 public function testChannel()
 {
     $permission = SlackChannelPublic::where('channel_id', '=', 'C1Z920QKC')->first();
     $artifact = SlackChannel::find('C1Z920QKC');
     $this->assertEquals($artifact, $permission->channel);
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     SlackChannel::where('name', 'LIKE', 'mpdm-%')->where('is_group', true)->delete();
 }
Exemplo n.º 7
0
 public function testChannel()
 {
     $permission = SlackChannelAlliance::where('alliance_id', '=', 99000006)->first();
     $artifact = SlackChannel::find('C1Z920QKC');
     $this->assertEquals($artifact, $permission->channel);
 }
 public function testChannel()
 {
     $permission = SlackChannelCorporation::where('corporation_id', '=', 98413060)->first();
     $artifact = SlackChannel::find('C1Z920QKC');
     $this->assertEquals($artifact, $permission->channel);
 }