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

SUP-2117, Member profile page should be viewable even if you are not logged in #353

Merged
merged 1 commit into from
Oct 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions app/profile/about/about.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

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

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

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

profileVm.externalLinksPromise.then(function() {
vm.linkedExternalAccountsData = profileVm.linkedExternalAccountsData;
vm.linkedExternalAccounts = profileVm.linkedExternalAccounts;

// show section if user is viewing his/her own profile OR if we have data
vm.hasLinks = vm.linkedExternalAccounts.length;
//vm.hasLinks = _.any(_.valuesIn(_.omit(vm.linkedExternalAccountsData, ['userId', 'updatedAt','createdAt','createdBy','updatedBy','handle'])));
//vm.hasLinks = profileVm.linkedExternalAccounts.length;
vm.hasLinks = _.any(_.valuesIn(_.omit(vm.linkedExternalAccountsData, ['userId', 'updatedAt','createdAt','createdBy','updatedBy','handle'])));
vm.displaySection.externalLinks = profileVm.showEditProfileLink || vm.hasLinks;

// if user is authenticated, call for profiles end point
if (profileVm.isUser) {
var userId = UserService.getUserIdentity().userId;
ExternalAccountService.getLinkedExternalAccounts(userId).then(function(data) {
vm.linkedExternalAccounts = data;
profileVm.status.externalLinks = CONSTANTS.STATE_READY;
}).catch(function(err) {
profileVm.status.externalLinks = CONSTANTS.STATE_ERROR;
});
} else {
vm.linkedExternalAccounts = [];
// remove all keys except the provider keys
var accounts = _.omit(vm.linkedExternalAccountsData, ['userId', 'updatedAt','createdAt','createdBy','updatedBy','handle']);
// populate the externalLinks for external-account-data directive with info from ext accounts data
for(var provider in accounts) {
if (accounts[provider]) {
vm.linkedExternalAccounts.push({
providerType: provider
});
}
}
profileVm.status.externalLinks = CONSTANTS.STATE_READY;
}
});

profileVm.statsPromise.then(function() {
Expand Down
13 changes: 4 additions & 9 deletions app/profile/profile.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

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

ProfileCtrl.$inject = ['CONSTANTS', '$log',
ProfileCtrl.$inject = ['CONSTANTS', '$log', '$q',
'TcAuthService', 'UserService', 'ProfileService', 'ChallengeService', 'ExternalAccountService',
'userHandle', 'profile', 'ngDialog'
];

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


vm.externalLinksPromise = ExternalAccountService.getLinkedExternalAccounts(profile.userId).then(function(data) {
vm.linkedExternalAccounts = data;
vm.status.externalLinks = CONSTANTS.STATE_READY;
vm.externalLinksPromise = ExternalAccountService.getLinkedExternalLinksData(vm.userHandle).then(function(data) {
vm.linkedExternalAccountsData = data.plain();
}).catch(function(err) {
vm.status.externalLinks = CONSTANTS.STATE_ERROR;
});

ExternalAccountService.getLinkedExternalLinksData(vm.userHandle).then(function(data) {
vm.linkedExternalAccountsData = data.plain();
});

function activate() {
$log.debug('Calling ProfileController activate()');
// show edit profile link if user is authenticated and is viewing their own profile
Expand Down