mercredi 21 octobre 2015

Ember - Check if a member can view a group's information

I am trying to set up a groups page that will display the information about that group and the group members. If a user is in that group, it will display the information, but if a user is not in that group, it will not display the information and it will tell the user they are not a member of the group.

group-info/template.hbs

{{#if isMember}}
  'display group info'
{{else}}
  'do not display group info'
{{/if}}

When I arrive on the page and click on a group, the console prints out the correct array of IDs of members in that group. But when I click on a second group, it prints out the IDs from the first group, and when I click on a third group it prints out the IDs from the second group, and etc.

I'm not sure why the console information is always one click behind the group that I'm selecting. I've been trying to use the mapBy and map methods but I don't know if there is a better method to use or if I'm approaching this the wrong way.

group-info/component.js

import Ember from 'ember';

export default Ember.Component.extend({
  idOfIndividuals: Ember.computed.map('groupinfo.individuals', function(param, index) {
    return parseInt(param.id);
  }),
  isMember: Ember.computed('idOfIndividuals', 'session.individual_id', function() {
    console.log(this.get('idOfIndividuals'));
    console.log(this.get('session.individual_id'));
    return this.get('idOfIndividuals').contains(this.get('session.individual_id'));
  })
});

What is the best way to check that the logged-in user (session.individual_id) is a member of a group and able to view that group?




Aucun commentaire:

Enregistrer un commentaire