-
Notifications
You must be signed in to change notification settings - Fork 1.8k
fix: Restructure and update role-invite flow #3091
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
|
Server PR : fossasia/open-event-server#6015 |
|
@kushthedude @shreyanshdwivedi @mrsaicharan1 Please review! |
niranjan94
left a comment
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.
When doing async operations inside beforeModel ensure that beforeModel returns a promise that resolves once all async operations are completed.
a40b187
|
@CosmicCoder96 @niranjan94 After this change, I think the element of network requests is resolved. |
|
@mrsaicharan1 @shreyanshdwivedi @kushthedude Review please |
niranjan94
left a comment
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.
@uds5501 just putting an async before the function name isn't gonna solve this. The promise returned by beforeModel will still resolve before any of the two loaders within it complete their async task. You must await for those two tasks to complete.
|
@shreyanshdwivedi @kushthedude please review the code before pressing approve, other-wise no point in having peer-reviews. :) |
|
@uds5501 Can you make requested changes ASAP |
efdc61f
|
@niranjan94 @CosmicCoder96 please have a look now |
app/routes/public/role-invites.js
Outdated
| if (this.get('authManager.currentUser.email') === user.email) { | ||
| if (this.session.isAuthenticated) { | ||
| if (this.authManager.currentUser.email === user.email) { | ||
| this.loader |
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.
@niranjan94 adding an await here threw a build error so removed it, will it be any problem for now?
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.
@uds5501 you cannot use await without using async perhaps that's why you had gotten the error.
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.
But the implementation is still wrong. When using async-await, don't use then-catch.
Please read up more on async-await.
|
@niranjan94 actually the PR worked fine on my local. However didn't take a closer look on the code part. Will take care from next time |
app/routes/public/role-invites.js
Outdated
| if (this.get('authManager.currentUser.email') === user.email) { | ||
| if (this.session.isAuthenticated) { | ||
| if (this.authManager.currentUser.email === user.email) { | ||
| this.loader |
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.
@uds5501 you cannot use await without using async perhaps that's why you had gotten the error.
app/routes/public/role-invites.js
Outdated
| if (this.get('authManager.currentUser.email') === user.email) { | ||
| if (this.session.isAuthenticated) { | ||
| if (this.authManager.currentUser.email === user.email) { | ||
| this.loader |
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.
But the implementation is still wrong. When using async-await, don't use then-catch.
Please read up more on async-await.
@shreyanshdwivedi Thanks ! Always look at the code itself before running it locally. |
|
@niranjan94 in this commit I have implemented the second loader within another asynchronous function and user |
app/routes/public/role-invites.js
Outdated
| if (this.authManager.currentUser.email === user.email) { | ||
| await this.loader | ||
| .post('/role_invites/accept-invite', payload) | ||
| .then(invite => { |
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.
You're using await, then no need of then
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.
@iamareebjamal Okay, I see the error. Fixing it
|
@iamareebjamal @CosmicCoder96 @niranjan94 Please review!! |
niranjan94
left a comment
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.
@uds5501 there's a lot of code-duplication on this. I'm sure this can be much simpler and cleaner.
app/routes/public/role-invites.js
Outdated
| try { | ||
| let user = await this.loader.post('/role_invites/user', payload); | ||
| if (this.session.isAuthenticated) { | ||
| this.routingModel(payload, user); |
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.
If routingModel is asynchronous, shouldn't you be awaiting it too ?
|
Not related to this PR, but use const always unless you need mutable variables |
|
@niranjan94 I need a little help in reducing the repetition. this.transitionTo('register', {
queryParams: {
event : `${transition.resolvedModels.public.originalId}`,
inviteToken : `${transition.to.queryParams.token}`,
inviteEmail : `${user.email}`
}
});is the repeating transition which can simply be performed in the try {
if (this.authManager.currentUser.email === user.email) {
let invite = await this.loader.post('/role_invites/accept-invite', payload);
let getRoute = (invite.role === 'organiser' || invite.role === 'coorganizer') ? 'events.view' : 'public';
this.transitionTo(getRoute, invite.event);
return true
} else {
this.set('session.skipRedirectOnInvalidation', true);
this.session.invalidate();
return false
}
}and wanted to utilise this value to remove this redundant transition but I can't seem to be able to synchronise it. |
|
@uds5501 wouldn't this work ? This is an equivalent of your existing code but without code-repetition. import Route from '@ember/routing/route';
export default Route.extend({
async beforeModel(transition) {
const { token } = transition.to.queryParams;
const originalEventId = transition.resolvedModels.public.originalId;
const payload = {
data: { token }
};
const user = await this.loader.post('/role_invites/user', payload);
if (this.session.isAuthenticated) {
if (this.authManager.currentUser.email === user.email) {
return this.transitionTo(
['organiser', 'coorganizer'].includes(invite.role) ? 'events.view' : 'public',
await this.loader.post('/role_invites/accept-invite', payload)
);
}
this.set('session.skipRedirectOnInvalidation', true);
this.session.invalidate();
}
this.transitionTo('register', {
queryParams: {
event : originalEventId,
inviteToken : token,
inviteEmail : user.email
}
});
}
});Also, lack of try catch is intentional here. We're letting ember handle the error and render the error page. |
This should work! I will test it in my local and push the changes. |
|
@niranjan94 it just took a minor change otherwise your code worked. Please review! |
|
@niranjan94 @CosmicCoder96 please review |
mariobehling
left a comment
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.
Moderators and all roles need to be able to see the dashboard, but depending on the role they don't have access to certain subpages. Please check how role models work on the UI of widely used systems like wordpress. We need to work on the details of roles, but this issue appears with all roles.
If I am an organizer I also receive an error page after an invite. Please take care of the organizer/co-organizer role first and ensure it is working.
The issue description of the linked issue simply says "does not work". This is not what we expect from an issue. Please write in future what behavior is expected - exactly -. So it can be solved accordingly.
No invited user should be directed to the public page. All invited event roles should be able to see the dashboard.
|
@mariobehling For now, I have made sure that organiser and co-organisers don't get a 400 error when accepting role invites. @niranjan94 @kushthedude @shreyanshdwivedi @mrsaicharan1 , Please review this |
|
@uds5501 Any GIF or Demo of the following would be awesome |
|
@uds5501 Looks great, Just one more doubt what if the invite is of other roles, Is the user gets redirected to the event dashboard? |
@kushthedude |
If that's the case, I think the PR is good to go then! |

Fixes #2771
Changes proposed in this pull request:
Checklist
developmentbranch.