Skip to content

Commit

Permalink
Merge 5288136 into a1706d1
Browse files Browse the repository at this point in the history
  • Loading branch information
dinoboff committed Sep 27, 2016
2 parents a1706d1 + 5288136 commit b4190c2
Show file tree
Hide file tree
Showing 10 changed files with 226 additions and 428 deletions.
2 changes: 1 addition & 1 deletion database/security-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@
},
"lastUpdateRequest": {
".validate": "newData.val() === now",
".write": "auth !== null && root.child('classMentors/admins').child(auth.uid).val() === true"
".write": true
}
}
},
Expand Down
10 changes: 2 additions & 8 deletions database/test/profile.specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,10 @@ describe('profile', function() {
expect(auth.bob).can.patch(patch).to.path('/');
});

it('should allow admin to request some user service update', function() {
it('should allow any users to request other users update', function() {
const patch = requestPatch('bob');

expect(auth.admin).can.patch(patch).to.path('/');
});

it('should disallow users to request other users update', function() {
const patch = requestPatch('bob');

expect(auth.alice).cannot.patch(patch).to.path('/');
expect(auth.alice).can.patch(patch).to.path('/');
});
});

Expand Down
8 changes: 4 additions & 4 deletions src/classmentors/components/profiles/profiles-view-edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h3 ng-if="ctrl.profile.user.school &amp;&amp; ctrl.profile.user.school.type !=

<div flex="66" flex-sm="100">

<clm-service-card service-id="freeCodeCamp" public-id="ctrl.profile.$id"
<clm-service-card service-id="freeCodeCamp" public-id="ctrl.profile.$id" disable-refresh="ctrl.refreshTimeout"
profile-template="https://www.freecodecamp.com/{{name}}"
>
<clm-description>
Expand All @@ -45,7 +45,7 @@ <h3 ng-if="ctrl.profile.user.school &amp;&amp; ctrl.profile.user.school.type !=
</clm-description>
</clm-service-card>

<clm-service-card service-id="pivotalExpert" public-id="ctrl.profile.$id"
<clm-service-card service-id="pivotalExpert" public-id="ctrl.profile.$id" disable-refresh="ctrl.refreshTimeout"
profile-template="https://pivotal-expert.firebaseapp.com/#/profile/{{name}}"
>
<clm-description>
Expand All @@ -54,15 +54,15 @@ <h3 ng-if="ctrl.profile.user.school &amp;&amp; ctrl.profile.user.school.type !=
</clm-description>
</clm-service-card>

<clm-service-card service-id="codeCombat" public-id="ctrl.profile.$id"
<clm-service-card service-id="codeCombat" public-id="ctrl.profile.$id" disable-refresh="ctrl.refreshTimeout"
profile-template="https://codecombat.com/user/{{name}}"
>
<clm-description>
<a href="http://codecombat.com/" target="_blank">Code Combat</a>,
learn to Code JavaScript by Playing a Game.
</clm-description>
</clm-service-card>

</div>
</div>

Expand Down
6 changes: 3 additions & 3 deletions src/classmentors/components/profiles/profiles-view-show.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h3 ng-if="ctrl.profile.user.school" layout="row" layout-align="center center">

<div flex="66">

<clm-service-card service-id="freeCodeCamp" public-id="ctrl.profile.$id"
<clm-service-card service-id="freeCodeCamp" public-id="ctrl.profile.$id" disable-refresh="ctrl.refreshTimeout"
profile-template="https://www.freecodecamp.com/{{name}}"
>
<clm-description>
Expand All @@ -23,7 +23,7 @@ <h3 ng-if="ctrl.profile.user.school" layout="row" layout-align="center center">
</clm-description>
</clm-service-card>

<clm-service-card service-id="pivotalExpert" public-id="ctrl.profile.$id"
<clm-service-card service-id="pivotalExpert" public-id="ctrl.profile.$id" disable-refresh="ctrl.refreshTimeout"
profile-template="https://pivotal-expert.firebaseapp.com/#/profile/{{name}}"
>
<clm-description>
Expand All @@ -32,7 +32,7 @@ <h3 ng-if="ctrl.profile.user.school" layout="row" layout-align="center center">
</clm-description>
</clm-service-card>

<clm-service-card service-id="codeCombat" public-id="ctrl.profile.$id"
<clm-service-card service-id="codeCombat" public-id="ctrl.profile.$id" disable-refresh="ctrl.refreshTimeout"
profile-template="https://codecombat.com/user/{{name}}"
>
<clm-description>
Expand Down
44 changes: 30 additions & 14 deletions src/classmentors/components/profiles/profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,36 +126,38 @@ clmShowProfileInitialDataResolver.$inject = ['$q', '$route', 'spfAuth', 'spfAuth
*
*/
function ClmProfileCtrl(
$log, $q, $timeout, $route, spfAuthData, spfNavBarService, initialData, clmDataStore, spfAlert
$log, $q, $timeout, $route, spfAuthData, spfNavBarService, initialData, clmDataStore, spfAlert, clmRefreshTimout
) {
const refreshLabel = 'Refresh Achievements';
const waitingLabel = 'Waiting...';
var self = this;
var menu = [];
var refreshButton = {
title: refreshLabel,
onClick: () => this.refreshAllService(),
icon: 'loop',
disabled: false
};
var menu = [refreshButton];

this.auth = initialData.auth;
this.currentUser = initialData.currentUser;
this.currentUserProfile = initialData.currentUserProfile;
this.profile = initialData.profile;
this.settings = initialData.settings;
this.canRefresh = true;
this.refreshTimeout = undefined;

if (
this.profile &&
this.profile.$id &&
this.currentUser &&
this.currentUser.publicId === this.profile.$id
) {
menu = [refreshButton, {
menu.push({
title: 'Edit',
onClick: () => (this.profileNeedsUpdate = true),
icon: 'create'
}];
});
}

spfNavBarService.update('Profile', undefined, menu);
Expand Down Expand Up @@ -203,7 +205,10 @@ function ClmProfileCtrl(
};

this.refreshAllService = () => {
this.disableRefresh();

clmDataStore.services.refresh(this.profile).catch(err => {
this.canRefresh = true;
$log.error(err);
spfAlert.error('Failed to refresh achievements.');
});
Expand All @@ -212,23 +217,34 @@ function ClmProfileCtrl(
this.disableRefresh = () => {
refreshButton.title = waitingLabel;
refreshButton.disabled = true;
this.canRefresh = false;

clmDataStore.services.canRefresh(this.profile).catch(
err => $log.error(err)
).then(() => {
refreshButton.title = refreshLabel;
refreshButton.disabled = false;
});
this.refreshTimeout = $timeout(clmRefreshTimout);
this.refreshTimeout.then(
() => this.enableRefresh()
);
};

const servicesRef = clmDataStore.services.ref(this.profile.$id);
const serviceUpdatehandler = servicesRef.on('value', () => this.disableRefresh());
this.enableRefresh = () => {
refreshButton.title = refreshLabel;
refreshButton.disabled = false;

if (this.refreshTimeout) {
$timeout.cancel(this.refreshTimeout);
this.refreshTimeout = undefined;
}
};

this.$onDestroy = () => servicesRef.off('value', serviceUpdatehandler);
this.$onDestroy = () => {
if (this.refreshTimeout) {
$timeout.cancel(this.refreshTimeout);
this.refreshTimeout = undefined;
}
};
}

ClmProfileCtrl.$inject = [
'$log', '$q', '$timeout', '$route',
'spfAuthData', 'spfNavBarService',
'initialData', 'clmDataStore', 'spfAlert'
'initialData', 'clmDataStore', 'spfAlert', 'clmRefreshTimout'
];
Loading

0 comments on commit b4190c2

Please sign in to comment.