Skip to content

Back end for link sharing #759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 12, 2019
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
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"phpunit.args": [
"--configuration", "test/php/phpunit.xml"
]
"--configuration",
"test/php/phpunit.xml"
],
"phpcs.composerJsonPath": "src"
}
68 changes: 68 additions & 0 deletions src/Api/Model/Shared/Command/ProjectCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,4 +344,72 @@ public static function projectCodeExists($code)

return $project->readByProperties(array('projectCode' => $code));
}

/**
* @param string $projectId
* @param string $defaultRole
* @return string invite link to project
*/
public static function createInviteLink($projectId, $defaultRole)
{
$project = ProjectModel::getById($projectId);

$newAuthToken = $project->generateNewInviteToken();
$project->setInviteTokenDefaultRole($defaultRole);

$project->write();

return $project->website()->baseUrl() . '/invite/' . $newAuthToken;
}

/**
* @param string $projectId
* @param string $defaultRole
* @return string invite link to project
*/
public static function getInviteLink($projectId)
{
// TODO: check that invite token exists. If not, throw exception.
// TODO: check that project invite sharing is enabled. If not, throw exception if disabled.
$project = ProjectModel::getById($projectId);
return $project->website()->baseUrl() . '/invite/' . $project->inviteToken->token;
}

/**
* Removes the invite token from a project
* @param $projectId
*/
public static function disableInviteToken($projectId)
{
$project = ProjectModel::getById($projectId);
$project->inviteToken->token = '';
$project->write();
}

/**
* Updates the role associated with an invite token
* @param $projectId
* @param $newRole the roleName to associate with
*/
public static function updateInviteTokenRole($projectId, $newRole)
{
$project = ProjectModel::getById($projectId);
$project->setInviteTokenDefaultRole($newRole);
$project->write();
}

/**
* Add a user to the project based on the invite token for the project
* @param $projectId
* @param $newRole the value of the roles array to link
*/
public static function useInviteToken($userId, $projectId) {
$model = ProjectModel::getById($projectId);
$model->addUserByInviteToken($userId);
$model->write();

$user = new UserModel($userId);
$user->addProject($projectId);
$user->write();
}
}
Loading