Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit e22bafe

Browse files
author
vikasrohit
committed
SUP-2117, Member profile page should be viewable even if you are not logged in
-- Fixed
1 parent 7ccf729 commit e22bafe

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

app/profile/about/about.controller.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
angular.module('tc.profile').controller('ProfileAboutController', ProfileAboutController);
55

6-
ProfileAboutController.$inject = ['$log', '$scope', 'ProfileService', 'ExternalAccountService'];
6+
ProfileAboutController.$inject = ['$log', '$scope', 'ProfileService', 'ExternalAccountService', 'UserService', 'CONSTANTS'];
77

8-
function ProfileAboutController($log, $scope, ProfileService, ExternalAccountService, UserService) {
8+
function ProfileAboutController($log, $scope, ProfileService, ExternalAccountService, UserService, CONSTANTS) {
99
var vm = this;
1010
$log = $log.getInstance("ProfileAboutController");
1111
var profileVm = $scope.$parent.profileVm;
@@ -24,11 +24,35 @@
2424

2525
profileVm.externalLinksPromise.then(function() {
2626
vm.linkedExternalAccountsData = profileVm.linkedExternalAccountsData;
27-
vm.linkedExternalAccounts = profileVm.linkedExternalAccounts;
27+
2828
// show section if user is viewing his/her own profile OR if we have data
29-
vm.hasLinks = vm.linkedExternalAccounts.length;
30-
//vm.hasLinks = _.any(_.valuesIn(_.omit(vm.linkedExternalAccountsData, ['userId', 'updatedAt','createdAt','createdBy','updatedBy','handle'])));
29+
//vm.hasLinks = profileVm.linkedExternalAccounts.length;
30+
vm.hasLinks = _.any(_.valuesIn(_.omit(vm.linkedExternalAccountsData, ['userId', 'updatedAt','createdAt','createdBy','updatedBy','handle'])));
3131
vm.displaySection.externalLinks = profileVm.showEditProfileLink || vm.hasLinks;
32+
33+
// if user is authenticated, call for profiles end point
34+
if (profileVm.isUser) {
35+
var userId = UserService.getUserIdentity().userId;
36+
ExternalAccountService.getLinkedExternalAccounts(userId).then(function(data) {
37+
vm.linkedExternalAccounts = data;
38+
profileVm.status.externalLinks = CONSTANTS.STATE_READY;
39+
}).catch(function(err) {
40+
profileVm.status.externalLinks = CONSTANTS.STATE_ERROR;
41+
});
42+
} else {
43+
vm.linkedExternalAccounts = [];
44+
// remove all keys except the provider keys
45+
var accounts = _.omit(vm.linkedExternalAccountsData, ['userId', 'updatedAt','createdAt','createdBy','updatedBy','handle']);
46+
// populate the externalLinks for external-account-data directive with info from ext accounts data
47+
for(var provider in accounts) {
48+
if (accounts[provider]) {
49+
vm.linkedExternalAccounts.push({
50+
providerType: provider
51+
});
52+
}
53+
}
54+
profileVm.status.externalLinks = CONSTANTS.STATE_READY;
55+
}
3256
});
3357

3458
profileVm.statsPromise.then(function() {

app/profile/profile.controller.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33

44
angular.module('tc.profile').controller('ProfileCtrl', ProfileCtrl);
55

6-
ProfileCtrl.$inject = ['CONSTANTS', '$log',
6+
ProfileCtrl.$inject = ['CONSTANTS', '$log', '$q',
77
'TcAuthService', 'UserService', 'ProfileService', 'ChallengeService', 'ExternalAccountService',
88
'userHandle', 'profile', 'ngDialog'
99
];
1010

11-
function ProfileCtrl(CONSTANTS, $log, TcAuthService, UserService, ProfileService, ChallengeService, ExternalAccountService, userHandle, profile, ngDialog) {
11+
function ProfileCtrl(CONSTANTS, $log, $q, TcAuthService, UserService, ProfileService, ChallengeService, ExternalAccountService, userHandle, profile, ngDialog) {
1212
var vm = this;
1313
// set profile to the object that was resolved
1414
vm.profile = profile;
@@ -58,17 +58,12 @@
5858
});
5959

6060

61-
vm.externalLinksPromise = ExternalAccountService.getLinkedExternalAccounts(profile.userId).then(function(data) {
62-
vm.linkedExternalAccounts = data;
63-
vm.status.externalLinks = CONSTANTS.STATE_READY;
61+
vm.externalLinksPromise = ExternalAccountService.getLinkedExternalLinksData(vm.userHandle).then(function(data) {
62+
vm.linkedExternalAccountsData = data.plain();
6463
}).catch(function(err) {
6564
vm.status.externalLinks = CONSTANTS.STATE_ERROR;
6665
});
6766

68-
ExternalAccountService.getLinkedExternalLinksData(vm.userHandle).then(function(data) {
69-
vm.linkedExternalAccountsData = data.plain();
70-
});
71-
7267
function activate() {
7368
$log.debug('Calling ProfileController activate()');
7469
// show edit profile link if user is authenticated and is viewing their own profile

0 commit comments

Comments
 (0)