Skip to content

Commit 6db6d47

Browse files
authored
Merge pull request #119 from abought/fix/trell18-date-changing
[rfr] Don't modify the session record just to show "you already completed" page
2 parents db6c9fb + 7cce443 commit 6db6d47

File tree

2 files changed

+76
-75
lines changed

2 files changed

+76
-75
lines changed

app/controllers/participate/login.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default Ember.Controller.extend({
3030
var surveyController = Ember.getOwner(this).lookup('controller:participate');
3131
surveyController.set('studyId', attrs.password);
3232
surveyController.set('participantId', attrs.username);
33+
this.set('authenticating', false);
3334
this.transitionToRoute('participate.survey.consent');
3435
})
3536
.catch((e) => {

app/routes/participate/survey.js

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,85 +4,85 @@ import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-rout
44
import config from 'ember-get-config';
55

66
export default Ember.Route.extend(AuthenticatedRouteMixin, {
7-
_experiment: null,
8-
_session: null,
9-
store: Ember.inject.service(),
10-
currentUser: Ember.inject.service(),
11-
i18n: Ember.inject.service(),
7+
_experiment: null,
8+
_session: null,
9+
store: Ember.inject.service(),
10+
currentUser: Ember.inject.service(),
11+
i18n: Ember.inject.service(),
1212

13-
_getExperiment() {
14-
return this.store.find('experiment', config.studyId);
15-
},
16-
_getSession(params, experiment) { // jshint ignore: line
17-
return this.get('currentUser').getCurrentUser().then(([account, profile]) => {
18-
return account.pastSessionsFor(experiment, profile).then((pastSessions) => {
19-
if (pastSessions.get('length') === 0) {
20-
return this.store.createRecord(experiment.get('sessionCollectionId'), {
21-
experimentId: experiment.id,
22-
profileId: account.get('username') + '.' + account.get('username'),
23-
completed: false,
24-
feedback: '',
25-
hasReadFeedback: '',
26-
expData: {},
27-
sequence: []
28-
});
29-
}
30-
return pastSessions.objectAt(0);
31-
});
32-
});
33-
},
34-
model(params) {
35-
return new Ember.RSVP.Promise((resolve, reject) => {
36-
this._getExperiment(params).then((experiment) => {
37-
this._getSession(params, experiment).then((session) => {
38-
if (session.get('completed') && config.featureFlags.showStudyCompletedPage) {
39-
this.transitionTo('participate.complete');
40-
}
41-
this.set('_experiment', experiment);
42-
session.set('experimentVersion', '');
13+
_getExperiment() {
14+
return this.store.find('experiment', config.studyId);
15+
},
16+
_getSession(params, experiment) { // jshint ignore: line
17+
let username;
18+
return this.get('currentUser').getCurrentUser()
19+
.then(([account, profile]) => {
20+
username = account.get('username');
21+
return account.pastSessionsFor(experiment, profile);
22+
}).then((pastSessions) => {
23+
if (pastSessions.get('length') !== 0) {
24+
return pastSessions.objectAt(0);
25+
}
26+
return this.store.createRecord(experiment.get('sessionCollectionId'), {
27+
experimentId: experiment.id,
28+
profileId: username + '.' + username,
29+
completed: false,
30+
feedback: '',
31+
hasReadFeedback: '',
32+
expData: {},
33+
sequence: []
34+
});
35+
});
36+
},
37+
beforeModel(transition) {
38+
this._super(transition);
4339

44-
if (!session.get('extra')) {
45-
session.set('extra', {});
46-
}
40+
let locale;
41+
try {
42+
locale = this.controllerFor('participate').get('locale');
43+
} catch (e) {}
44+
if (!locale) {
45+
this.transitionTo('participate.login');
46+
} else {
47+
this.transitionTo('participate.survey.consent');
48+
}
49+
},
50+
model(params) {
51+
return this._getExperiment(params).then((experiment) => {
52+
this.set('_experiment', experiment);
53+
return this._getSession(params, experiment);
54+
});
55+
},
4756

48-
session.set('extra.locale', this.get('i18n.locale')); // The user's locale
49-
session.set('extra.studyId', this.controllerFor('participate').get('studyId')); // The siteID for the location where the study was taken
50-
session.save().then(() => {
51-
this.set('_session', session);
52-
resolve(session);
53-
});
57+
afterModel(session) {
58+
if (session.get('completed') && config.featureFlags.showStudyCompletedPage) {
59+
return this.transitionTo('participate.complete');
60+
}
61+
if (!session.get('extra')) {
62+
session.set('extra', {});
63+
}
64+
session.setProperties({
65+
experimentVersion: '',
66+
'extra.locale' : this.get('i18n.locale'), // The user's locale
67+
'extra.studyId': this.controllerFor('participate').get('studyId'), // The siteID for the location where the study was taken
68+
});
69+
return session.save().then(() => this.set('_session', session));
70+
},
71+
activate () {
72+
let session = this.get('_session');
73+
// Include session ID in any raven reports that occur during the experiment
74+
this.get('raven').callRaven('setExtraContext', {
75+
sessionID: session.id,
76+
participantID: this.controllerFor('participate').get('participantId'),
77+
locale: this.controllerFor('participate').get('locale')
5478
});
55-
}).catch(reject);
56-
});
57-
},
58-
beforeModel(transition) {
59-
this._super(transition);
79+
return this._super(...arguments);
80+
},
81+
setupController(controller, session) {
82+
this._super(controller, session);
6083

61-
var locale;
62-
try {
63-
locale = this.controllerFor('participate').get('locale');
64-
} catch (e) {}
65-
if (!locale) {
66-
this.transitionTo('participate.login');
67-
} else {
68-
this.transitionTo('participate.survey.consent');
84+
controller.set('experiment', this.get('_experiment'));
85+
controller.set('session', session);
86+
controller.set('pastSessions', []);
6987
}
70-
},
71-
activate () {
72-
let session = this.get('_session');
73-
// Include session ID in any raven reports that occur during the experiment
74-
this.get('raven').callRaven('setExtraContext', {
75-
sessionID: session.id,
76-
participantID:this.controllerFor('participate').get('participantId'),
77-
locale: this.controllerFor('participate').get('locale')
78-
});
79-
return this._super(...arguments);
80-
},
81-
setupController(controller, session) {
82-
this._super(controller, session);
83-
84-
controller.set('experiment', this.get('_experiment'));
85-
controller.set('session', session);
86-
controller.set('pastSessions', []);
87-
}
8888
});

0 commit comments

Comments
 (0)