Skip to content

Commit

Permalink
Fixed intercom user add
Browse files Browse the repository at this point in the history
  • Loading branch information
willdoran committed Jun 25, 2017
1 parent b1749bc commit 822bdf0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
25 changes: 16 additions & 9 deletions application/classes/Ushahidi/Listener/IntercomAdminListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,35 @@ public function handle(EventInterface $event, $user = null)
$intercomAppToken = getenv('INTERCOM_APP_TOKEN');
$domain = service('site');
$company = [
"id" => $domain
"company_id" => $domain
];

if ($intercomAppToken && empty($domain)) {
if ($intercomAppToken && !empty($domain)) {

$client = new IntercomClient($intercomAppToken, null);

try {
$client->users->update([
$intercom_user = [
"email" => $user->email,
"created_at" => $user->created,
"user_id" => $domain . '_' . $user->id,
"realname" => $user->realname,
"last_login" => $user->last_login,
"role" => $user->role,
"language" => $user->language,
"name" => $user->realname,
"companies" => [
$company
],
"custom_attributes" => [
"last_login" => $user->last_login,
"logins" => $user->logins,
"role" => $user->role,
"language" => $user->language,
]
]);
];

$client->users->update($intercom_user);

} catch(ClientException $e) {
Kohana::$log->add(Log::ERROR, print_r($e,true));
$message = $e->getMessage();
Kohana::$log->add(Log::ERROR, print_r($message,true));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function handle(EventInterface $event, $data = null)
$intercomAppToken = getenv('INTERCOM_APP_TOKEN');
$domain = service('site');

if ($intercomAppToken && empty($domain)) {
if ($intercomAppToken && !empty($domain)) {

try {
$client = new IntercomClient($intercomAppToken, null);
Expand All @@ -37,7 +37,7 @@ public function handle(EventInterface $event, $data = null)
"custom_attributes" => $data
];
// Update company
$thing = $client->companies->create($company);
$client->companies->create($company);

} catch(ClientException $e) {
Kohana::$log->add(Log::ERROR, print_r($e,true));
Expand Down
9 changes: 7 additions & 2 deletions application/classes/Ushahidi/Repository/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function createWithHash(Entity $entity)
];
$entity->setState($state);
if ($entity->role === 'admin') {
$this->updateIntercomAdminUsers($state);
$this->updateIntercomAdminUsers($entity);
}

return parent::create($entity);
Expand All @@ -96,7 +96,12 @@ public function update(Entity $entity)
$state['password'] = $this->hasher->hash($entity->password);
}

return parent::update($entity->setState($state));
$entity->setState($state);
if ($entity->role === 'admin') {
$this->updateIntercomAdminUsers($entity);
}

return parent::update($entity);
}

// SearchRepository
Expand Down

0 comments on commit 822bdf0

Please sign in to comment.