Skip to content

Commit

Permalink
add comments and points
Browse files Browse the repository at this point in the history
  • Loading branch information
DawidDamek committed Sep 17, 2023
1 parent a0d4ade commit 7d7e8cd
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app/abilities/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { inject as service } from '@ember/service';
import { Ability } from 'ember-can';

export default class pageAbility extends Ability {
@service session;

get canVisit() {
return Boolean(this.session.currentUser);
}
}
12 changes: 12 additions & 0 deletions app/abilities/user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { inject as service } from '@ember/service';
import { Ability } from 'ember-can';

export default class pageAbility extends Ability {
@service session;

get canSeeSecrets() {
const { id, isAdmin } = this.session.currentUser;
const userID = this.model;
return Boolean(id === userID || isAdmin);
}
}
4 changes: 2 additions & 2 deletions app/components/game-carousel/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
<span class='visually-hidden'>Next</span>
</button>
</div>
<LinkTo @route='home.games'>
<LinkTo @route='home.games' class={{if (cannot 'press button') 'pe-none'}}>
<Shared::Button
class='btn-primary'
class={{if (can 'press button') 'btn-primary' 'btn-danger'}}
@label='Check the games'
disabled={{cannot 'press button'}}
/>
Expand Down
6 changes: 4 additions & 2 deletions app/components/user/details/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
{{@user.id}}</li>
<li data-test-user-email class='list-group-item'>Email:
{{@user.email}}</li>
<li data-test-user-password class='list-group-item'>Password:
{{@user.password}}</li>
{{#if (can 'see secrets in user' @user.id)}}
<li data-test-user-password class='list-group-item'>Password:
{{@user.password}}</li>
{{/if}}
</ul>
</div>
6 changes: 5 additions & 1 deletion app/home/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { inject as service } from '@ember/service';
export default class HomeRoute extends Route {
@service router;
@service session;
@service abilities;

async beforeModel() {
const { isLoggedIn } = this.session;
if (!isLoggedIn) {
this.router.transitionTo('/login');
return;
}

if (this.abilities.cannot('visit page')) {
this.router.transitionTo('/login');
return;
}
await this.session.setCurrentUser();
}
}

0 comments on commit 7d7e8cd

Please sign in to comment.