Skip to content

Commit

Permalink
Add collab command mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmith4-godaddy committed Oct 29, 2024
1 parent 5916ff4 commit cccd52e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 8 deletions.
20 changes: 19 additions & 1 deletion src/API/Accounts/AccountsClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,25 @@ public function getCollaboratorAccess($accessToken, $accountId)
return $this->guzzle($this->getBearerTokenMiddleware($accessToken))->get("accounts/{$accountId}/access");
}

public function removeCollaboratorsForApp($accessToken, $accountId, $appId)
public function addCollaboratorToAcct(string $accessToken, string $newAcctEmail, string $newAcctName, int $newAcctRole, int $newAcctId)
{
return $this->guzzle($this->getBearerTokenMiddleware($accessToken))
->post("accounts/{$newAcctId}/collaborators", ['json' => [
'email' => $newAcctEmail,
'name' => $newAcctName,
'role' => $newAcctRole,
'appId' => 0
],
]);
}

public function removeCollaboratorFromAcct(string $accessToken, string $acctId, string $collabId) {
$role = 6; // this is a temp hack, need to actually get user's role somehow
return $this->guzzle($this->getBearerTokenMiddleware($accessToken))
->delete("accounts/{$acctId}/collaborators/{$collabId}/{$role}/0");
}

public function removeCollaboratorsForApp(string $accessToken, string $accountId, int $appId)
{
return $this->guzzle($this->getBearerTokenMiddleware($accessToken))
->delete("accounts/{$accountId}/collaborators/apps/{$appId}");
Expand Down
57 changes: 57 additions & 0 deletions src/Command/Accounts/AddCollabToAcctCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Pagely\AtomicClient\Command\Accounts;

use Pagely\AtomicClient\API\Accounts\AccountsClient;
use Pagely\AtomicClient\API\AuthApi;
use Pagely\AtomicClient\Command\Command;
use Pagely\AtomicClient\Command\OauthCommandTrait;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class AddCollabToAcctCommand extends Command
{
use OauthCommandTrait;

/**
* @var AccountsClient
*/
protected $api;

public function __construct(AuthApi $authApi, AccountsClient $apps, $name = 'account:collabs:add-to-account')
{
$this->authClient = $authApi;
$this->api = $apps;
parent::__construct($name);
}

public function configure()
{
parent::configure();
$this
->setDescription('Add collaborator to account')
->addArgument('email', InputArgument::REQUIRED, 'Email address')
->addArgument('accountId', InputArgument::REQUIRED, 'Account ID')
->addArgument('roleId', InputArgument::REQUIRED, 'Role ID')
->addArgument('name', InputArgument::OPTIONAL, 'Display Name', 0)
;
$this->addOauthOptions();
}

public function execute(InputInterface $input, OutputInterface $output): int
{
$newAcctEmail = $input->getArgument('email');
$newAcctName = $input->getArgument('name');
if ($newAcctName === 0) { $newAcctName = $input->getArgument('email'); }
$newAcctAppId = $input->getArgument('accountId');
$newAcctRole = $input->getArgument('roleId');
$token = $this->token->token;

$r = $this->api->addCollaboratorToAcct($token,
$newAcctEmail, $newAcctName, $newAcctRole, $newAcctAppId);
$output->writeln(json_encode(json_decode($r->getBody()->getContents()), JSON_PRETTY_PRINT));

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class RemoveCollabCommand extends Command
class RemoveCollabFromAcctCommand extends Command
{
use OauthCommandTrait;

Expand All @@ -19,7 +19,7 @@ class RemoveCollabCommand extends Command
*/
protected $api;

public function __construct(AuthApi $authApi, AccountsClient $apps, $name = 'account:collabs:remove')
public function __construct(AuthApi $authApi, AccountsClient $apps, $name = 'account:collabs:remove-from-acct')
{
$this->authClient = $authApi;
$this->api = $apps;
Expand All @@ -33,21 +33,18 @@ public function configure()
->setDescription('Remove collaborator from account (BROKEN)')
->addArgument('accountId', InputArgument::REQUIRED, 'Account ID')
->addArgument('collabId', InputArgument::REQUIRED, 'Collab User ID')
->addArgument('appId', InputArgument::OPTIONAL, 'App ID', 0)
;
$this->addOauthOptions();
}

// TODO this needs to look up the provided info and get the user's current role, so we can feed that
// to removeAccess. For now treat it as broken.
public function execute(InputInterface $input, OutputInterface $output): int
{
$accountId = $input->getArgument('accountId');
$collabId = $input->getArgument('collabId');
$appId = $input->getArgument('appId');
$token = $this->token->token;

$r = $this->api->removeAccess($token, $accountId, $collabId, 8, $appId);
// this NEEDS that function! trust me!
$r = $this->api->removeCollaboratorFromAcct($token, $accountId, $collabId);
$output->writeln(json_encode(json_decode($r->getBody()->getContents()), JSON_PRETTY_PRINT));

return 0;
Expand Down

0 comments on commit cccd52e

Please sign in to comment.