Skip to content

Commit 03cb4d5

Browse files
committed
Return id instead of model when looking up by invite token
And minor polish
1 parent a95f338 commit 03cb4d5

File tree

6 files changed

+12
-23
lines changed

6 files changed

+12
-23
lines changed

src/Api/Model/Shared/InviteToken.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,4 @@ public function __construct() {
1616

1717
/** @var LexRole */
1818
public $defaultRole;
19-
20-
/** @var boolean */
21-
public $isEnabled;
2219
}

src/Api/Model/Shared/ProjectModel.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ public function addUser($userId, $role)
220220
/**
221221
* Adds the $userId as a member of this project.
222222
* @param string $userId
223-
* @param string $role The system role the user has.
224223
* @see Roles;
225224
*/
226225
public function addUserByInviteToken($userId)
@@ -463,24 +462,20 @@ public static function getById($projectId)
463462
* @return ProjectModel
464463
* @throws ResourceNotAvailableException
465464
*/
466-
public static function getByInviteToken($token)
465+
public static function getIdByInviteToken($token)
467466
{
468467
$model = new ProjectModel();
469468
$model->readByProperty('inviteToken.token', $token);
470469
switch ($model->appName) {
471470
case 'sfchecks':
472-
return new SfchecksProjectModel($model->id->id);
473471
case 'rapuma':
474-
return new RapumaProjectModel($model->id->id);
475472
case 'lexicon':
476-
return new LexProjectModel($model->id->id);
477473
case 'translate':
478-
return new TranslateProjectModel($model->id->id);
479474
case 'semdomtrans':
480-
return new SemDomTransProjectModel($model->id->id);
475+
return $model->id->id;
481476
default:
482477
throw new ResourceNotAvailableException(
483-
"inviteToken '$token' could not be found when calling ProjectModel::getByInviteToke()");
478+
"inviteToken '$token' could not be found when calling ProjectModel::getIdByInviteToken()");
484479
}
485480
}
486481

src/Site/Controller/App.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
use Api\Library\Shared\SilexSessionHelper;
88
use Api\Library\Shared\Website;
99
use Api\Model\Languageforge\LfProjectModel;
10-
use Api\Model\Shared\Command\ProjectCommands;
1110
use Api\Model\Shared\ProjectModel;
11+
use Api\Model\Shared\Command\ProjectCommands;
1212
use Api\Model\Shared\UserModel;
1313
use Silex\Application;
1414
use Symfony\Component\HttpFoundation\Request;
@@ -27,6 +27,7 @@ public function view(
2727
/** @noinspection PhpUnusedParameterInspection */
2828
Request $request, Application $app, $appName, $projectId = ''
2929
) {
30+
// Check if an invite token should be processed
3031
if (($appName == LfProjectModel::LEXICON_APP || $appName == 'projects') && $app['session']->get('inviteToken'))
3132
{
3233
try
@@ -164,13 +165,13 @@ private function processInviteToken(Application $app)
164165
{
165166
try
166167
{
167-
$model = ProjectModel::getByInviteToken($app['session']->get('inviteToken'));
168+
$projectId = ProjectModel::getIdByInviteToken($app['session']->get('inviteToken'));
168169
} catch (ResourceNotAvailableException $e)
169170
{
170171
throw new ResourceNotAvailableException('This invite link is not valid, it may have been disabled. Please check with your project manager.');
171172
}
172173
$userId = SilexSessionHelper::getUserId($app);
173-
ProjectCommands::useInviteToken($userId, $model->id->id);
174+
ProjectCommands::useInviteToken($userId, $projectId);
174175

175176
return $model->id->id;
176177
}

src/Site/Controller/Validate.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Site\Controller;
44

5-
use Api\Model\Languageforge\LfProjectModel;
65
use Api\Model\Shared\Command\ProjectCommands;
76
use Api\Library\Shared\SilexSessionHelper;
87
use Api\Library\Shared\Palaso\Exception\ResourceNotAvailableException;
@@ -40,7 +39,7 @@ public function processInviteAndRedirect(Application $app, $inviteToken = '')
4039
// Attempt to find the project with the given invite link
4140
try
4241
{
43-
$model = ProjectModel::getByInviteToken($inviteToken);
42+
$projectId = ProjectModel::getIdByInviteToken($inviteToken);
4443

4544
} catch (ResourceNotAvailableException $e)
4645
{
@@ -55,8 +54,8 @@ public function processInviteAndRedirect(Application $app, $inviteToken = '')
5554
// Add the user based on the invite token if they are logged in, otherwise redirect to login
5655
if ($this->isLoggedIn($app))
5756
{
58-
ProjectCommands::useInviteToken(SilexSessionHelper::getUserId($app), $model->id->id);
59-
return $app->redirect('/app/lexicon/' . $model->id->id);
57+
ProjectCommands::useInviteToken(SilexSessionHelper::getUserId($app), $projectId);
58+
return $app->redirect('/app/lexicon/' . $projectId);
6059
} else
6160
{
6261
$app['session']->set('inviteToken', $inviteToken);

src/angular-app/bellows/apps/public/login/login-app.component.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import * as angular from 'angular';
33
import { NoticeService } from '../../../core/notice/notice.service';
44

55
export class LoginAppController implements angular.IController {
6-
static $inject = ['silNoticeService', 'loginPath'];
7-
constructor(private notice: NoticeService, private loginPath: any) { }
6+
static $inject = ['silNoticeService'];
7+
constructor(private notice: NoticeService) { }
88

99
$onInit() {
1010
this.notice.checkUrlForNotices();

src/angular-app/bellows/apps/public/login/login-app.module.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,5 @@ export const LoginAppModule = angular
88
'ui.bootstrap',
99
CoreModule
1010
])
11-
.value('loginPath', "pasta")
12-
.value('last_username', '{{ last_username }}')
13-
// .controller('LoginCtrl', () => {})
1411
.component('loginApp', LoginAppComponent)
1512
.name;

0 commit comments

Comments
 (0)