Merge pull request #1371 from sharelatex/as-fix-dash-user-stubs

Handle UserStubs when linking projects with owners

GitOrigin-RevId: eb54df048ccf7fffd3feac14fbb5c8991efd47c3
This commit is contained in:
James Allen 2019-01-09 13:24:14 +00:00 committed by sharelatex
parent 1530062d00
commit b969526c19
4 changed files with 24 additions and 4 deletions

View file

@ -466,7 +466,7 @@ module.exports = ProjectController =
for user_id, _ of users
do (user_id) ->
jobs.push (callback) ->
User.findById user_id, "first_name last_name", (error, user) ->
UserGetter.getUserOrUserStubById user_id, { first_name: 1, last_name: 1 }, (error, user) ->
return callback(error) if error?
users[user_id] = user
callback()

View file

@ -33,6 +33,13 @@ div(class=titleClasses)
.col-xs-2
span.owner {{ownerName()}}
|  
i.fa.fa-question-circle.small(
ng-if="hasGenericOwnerName()"
tooltip="This project is owned by a user who hasnt yet migrated their account to Overleaf v2"
tooltip-append-to-body="true"
aria-hidden="true"
)
span(ng-if="isLinkSharingProject(project)")
|  
i.fa.fa-link.small(

View file

@ -691,13 +691,23 @@ define(['base'], function(App) {
$scope.isLinkSharingProject = project => project.source === 'token'
$scope.hasGenericOwnerName = () => {
const { first_name, last_name, email } = $scope.project.owner
return !first_name && !last_name && !email
}
$scope.ownerName = function() {
if ($scope.project.accessLevel === 'owner') {
return 'You'
} else if ($scope.project.owner != null) {
return [$scope.project.owner.first_name, $scope.project.owner.last_name]
.filter(n => n != null)
.join(' ')
const { first_name, last_name, email } = $scope.project.owner
if (first_name || last_name) {
return [first_name, last_name].filter(n => n != null).join(' ')
} else if (email) {
return email
} else {
return 'An Overleaf v1 User'
}
} else {
return 'None'
}

View file

@ -79,6 +79,7 @@ describe "ProjectController", ->
ipMatcherAffiliation: sinon.stub().returns({create: sinon.stub()})
@UserGetter =
getUser: sinon.stub().callsArgWith 2, null, {lastLoginIp: '192.170.18.2'}
getUserOrUserStubById: sinon.stub().callsArgWith 2, null, {}
@Modules =
hooks:
fire: sinon.stub()
@ -304,6 +305,8 @@ describe "ProjectController", ->
@users[@user._id] = @user # Owner
@UserModel.findById = (id, fields, callback) =>
callback null, @users[id]
@UserGetter.getUserOrUserStubById = (id, fields, callback) =>
callback null, @users[id]
@LimitationsManager.hasPaidSubscription.callsArgWith(1, null, false)
@TagsHandler.getAllTags.callsArgWith(1, null, @tags, {})