-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Conversation
db09a5f
to
03cb4d5
Compare
03cb4d5
to
989f348
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's looking very close to being done! You're almost there :)
Reviewed 13 of 15 files at r1, 2 of 2 files at r2.
Reviewable status: all files reviewed, 9 unresolved discussions (waiting on @Andrewdt97)
src/Api/Model/Shared/InviteToken.php, line 10 at r1 (raw file):
{ public function __construct() {
I think you can just leave out the empty constructor...not required.
src/Api/Model/Shared/ProjectModel.php, line 231 at r1 (raw file):
if(!$validRole) { throw new ResourceNotAvailableException('Project ' . $projectId . '\'s invite token is associated with nonexistant role '
spelling correction to "nonexistent" :)
src/Api/Model/Shared/ProjectModel.php, line 343 at r1 (raw file):
$this->inviteToken->defaultRole = $newRole; } else { throw new \InvalidArgumentException("A nonexistant role tried to be linked to an invite token.");
"nonexistent"
src/Api/Model/Shared/ProjectModel.php, line 468 at r1 (raw file):
readByProperty('inviteToken.token', $token);
does this actually work? Cool! I didn't realize that you could address a sub-property in the readByProperty method - I learn something new everyday...
src/Api/Model/Shared/Dto/RightsHelper.php, line 116 at r2 (raw file):
return true; case 'project_getInviteLink': return $this-userHasProjectRight(Domain::USERS + Operation::EDIT);
I'm thinking that the permissions for project_getInviteLink should actually be less than "manager" which is what this currently is. I think that
project_getInviteLink should have a base permission of project user, since anyone should be able to get the link once it is enabled, and not just managers. This function should simply return an existing link stored in the database, and generate one if it doesn't exist.
Seeing this line here now reminds me that we also need a project_generateLink or something similar.
src/angular-app/bellows/apps/public/login/login-app.component.ts, line 10 at r2 (raw file):
$onInit() { this.notice.checkUrlForNotices();
This feels like it should be in the $onInit() of the notice component itself, that way we don't have to remember to call this for every controller that uses the notice service, and also every instance of the notice component will automatically gain this feature.
src/Site/Controller/App.php, line 31 at r2 (raw file):
($appName == LfProjectModel::LEXICON_APP || $appName == 'projects')
We probably should not make this Lexicon app specific.
This whole section might fit better in Auth.php immediately after a successful login.
src/Site/Controller/Validate.php, line 16 at r2 (raw file):
class Validate extends Base { public static function check(Application $app, $validateKey = '')
should be public static function
src/Site/Controller/Validate.php, line 37 at r2 (raw file):
} public function processInviteAndRedirect(Application $app, $inviteToken = '')
should be public static function
d7f432a
to
c19468c
Compare
Add InivteLink object to ProjectModel . Add ProjectCommands for invite link generation Add API end points for link sharing operations Logged-in and valid token redirection Skeleton for proper redirection Display messages from URL Error messages for invalid invite link Make checkUrlForNotices() self-contained Also consumes the error message Add Array.includes polyfill to fix lots of Bugsnag errors Bugsnag was seeing errors mainly from IE11 and UC Browser. Also alphabetize the list of polyfill imports to make TSLint happy. add new build-agent to hosts tag this so it doesn't run for build-agents add buildagent install shell script fix hostnames Remove references to temp/jsonSessionData Remove references to temp/jsonSessionData Rendered entries now show correct part of speech Previously the optionLists data wasn't making it all the way to the dc-rendered component, so the component couldn't look up proper abbreviations for parts of speech and had to resort to using the key instead. This was mostly invisible for projects that had an English language user interface, but for non-English interfaces the English part-of-speech abbreviations were being wrongly shown. Fixed. This should fix https://jira.sil.org/browse/LF-319 Invite token is tracked through authentication process Polish for back end link sharing Convert login to angular component Return id instead of model when looking up by invite token And minor polish Add FlashBag support to Login app to pass E2E tests Return id instead of model when looking up by invite token And minor polish Distinguish between createInviteLink and getInviteLink Merge master
57de325
to
18726c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 5 of 7 files at r3, 4 of 4 files at r4, 2 of 2 files at r5.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @Andrewdt97)
Also added PHP Code Sniffer as dev dependency for use in VS Code project_getInviteLink can be accessed by project members The specific API security checks will be done inside the method
18726c8
to
a19a10e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have finished Andrew's PR on his behalf, and we will now carry on with the feature on Brant's branch.
Reviewed 5 of 5 files at r6.
Reviewable status:complete! all files reviewed, all discussions resolved
src/Api/Model/Shared/InviteToken.php, line 10 at r1 (raw file):
Previously, megahirt (Christopher Hirt) wrote…
I think you can just leave out the empty constructor...not required.
done.
src/Api/Model/Shared/ProjectModel.php, line 231 at r1 (raw file):
Previously, megahirt (Christopher Hirt) wrote…
spelling correction to "nonexistent" :)
done.
src/Api/Model/Shared/ProjectModel.php, line 343 at r1 (raw file):
Previously, megahirt (Christopher Hirt) wrote…
"nonexistent"
done.
src/angular-app/bellows/apps/public/login/login-app.component.ts, line 10 at r2 (raw file):
Previously, megahirt (Christopher Hirt) wrote…
This feels like it should be in the $onInit() of the notice component itself, that way we don't have to remember to call this for every controller that uses the notice service, and also every instance of the notice component will automatically gain this feature.
done.
src/Site/Controller/App.php, line 31 at r2 (raw file):
Previously, megahirt (Christopher Hirt) wrote…
($appName == LfProjectModel::LEXICON_APP || $appName == 'projects')
We probably should not make this Lexicon app specific.
This whole section might fit better in Auth.php immediately after a successful login.
Removed lexicon-specific code.
After investigation, the Auth.php file doesn't seem to contain the logic to determine if a login succeeded or not, which is what we need for this method. Leaving in App.php with a todo notice.
src/Site/Controller/Validate.php, line 37 at r2 (raw file):
Previously, megahirt (Christopher Hirt) wrote…
should be
public static function
I stand corrected. These are public controller methods that are mapped to Silex routes in index.php and it is expecting them not to be static.
Overview:
In order to better support users without emails and to streamline project sharing, it was determined that we should allow project managers to create invite links, which, upon accessing, add a user to a project with a specified role. This PR includes all of the back-end support for this link sharing. It includes three major partitions:
1. Creation and management of share link:
There are four new API calls related to the shareable link
'project_createInviteLink', [defaultRole<string>]: link<string>
'project_getInviteLink', []: link<string>
'project_disableInviteToken', []: void
'project_updateInviteTokenRole', [newRole<string>]: void
All API calls require
Domain::USERS + Operation::EDIT
permission exceptproject_getInviteLink
, which requiresDomain::PROJECTS + Operation::VIEW
permission. These calls invoke ProjectCommands that manipulate a ProjectModel's newinviteToken
object.2. Joining via the link:
All links point towards
https://<app>.org/invite/<invite code>
. When such a link is accessed, the server looks up a project with that invite code. If it is found and the user is logged in, the user is added to the project and redirected there. If it is found and the user is not logged in, there are taken to the login page with a message encouraging them to register. The invite code is tracked within$app['session']
and is processed when theprojects
orlexicon
apps are next accessed. If the project is not found, the user is show an error message on whatever page is appropriate to take them to based on their log-in status.3. Miscellaneous Refactors:
The following changes are also included to support the above features:
checkUrlForNotices()
method which checks the Url for base-64 encoded messages in theerrorMessage
,infoMessage
, andsuccessMessage
parameters.Screenshots:

Login page displaying a notice that a project could not be found with a given invite link.
Successfully being added to a project after signing up
Tests:
All PHP unit tests run (including new ones for the ProjectCommands)
E2E tests fail at
Update and store different username. Login with new credentials
. My guess is that this is due to the fact that migrating to an angular component from Silex on the login page no longer saves the username when logging out and logging back in. I am looking into as you read this.If you wish to manually test the invite link.
/invite/test
is set up to create a new project and handle it's invite code. Use branchfeature/linkSharingBackEndTestable
.Ideas for continued development:
This change is