Send user features and features switches to views where needed

This commit is contained in:
James Allen 2014-10-07 13:31:13 +01:00
parent 6c7c09075c
commit dbd85a05f1
6 changed files with 27 additions and 12 deletions

View file

@ -50,6 +50,10 @@ module.exports = AuthenticationController =
callback null, null
getLoggedInUser: (req, options = {allow_auth_token: false}, callback = (error, user) ->) ->
if typeof(options) == "function"
callback = options
options = {allow_auth_token: false}
if req.session?.user?._id?
query = req.session.user._id
else if req.query?.auth_token? and options.allow_auth_token

View file

@ -126,6 +126,8 @@ module.exports = ProjectController =
Project.findAllUsersProjects user_id, 'name lastUpdated publicAccesLevel archived owner_ref', cb
hasSubscription: (cb)->
LimitationsManager.userHasSubscriptionOrIsGroupMember req.session.user, cb
user: (cb) ->
User.findById user_id, "featureSwitches", cb
}, (err, results)->
if err?
logger.err err:err, "error getting data for project list page"
@ -133,6 +135,7 @@ module.exports = ProjectController =
logger.log results:results, user_id:user_id, "rendering project list"
tags = results.tags[0]
projects = ProjectController._buildProjectList results.projects[0], results.projects[1], results.projects[2]
user = results.user
ProjectController._injectProjectOwners projects, (error, projects) ->
return next(error) if error?
@ -141,6 +144,7 @@ module.exports = ProjectController =
priority_title: true
projects: projects
tags: tags
user: user
hasSubscription: results.hasSubscription
}
@ -210,6 +214,7 @@ module.exports = ProjectController =
referal_id : user.referal_id
subscription :
freeTrial: {allowed: allowedFreeTrial}
featureSwitches: user.featureSwitches
}
userSettings: {
mode : user.ace.mode
@ -281,8 +286,7 @@ defaultSettingsForAnonymousUser = (user_id)->
freeTrial:
allowed: true
featureSwitches:
dropbox: false
trackChanges: false
github: false
THEME_LIST = []
do generateThemeList = () ->

View file

@ -33,8 +33,7 @@ module.exports =
dropboxHandler.getUserRegistrationStatus user._id, (err, status)->
userIsRegisteredWithDropbox = !err? and status.registered
res.render 'user/settings',
title:'account_settings',
userHasDropboxFeature: user.features.dropbox
title:'account_settings'
userIsRegisteredWithDropbox: userIsRegisteredWithDropbox
user: user,
languages: Settings.languages,

View file

@ -33,8 +33,7 @@ UserSchema = new Schema
dropbox: { type:Boolean, default: Settings.defaultFeatures.dropbox }
}
featureSwitches : {
dropbox: {type:Boolean, default:true},
oldHistory: {type:Boolean}
github: {type: Boolean}
}
referal_id : {type:String, default:() -> uuid.v4().split("-")[0]}
refered_users: [ type:ObjectId, ref:'User' ]

View file

@ -96,14 +96,17 @@ block content
ng-disabled="changePasswordForm.$invalid"
) #{translate("change")}
hr.soften
hr
h3 #{translate("dropbox_integration")}
span.small
a(href='/help/kb/dropbox-2') (#{translate("learn_more")})
- if(!userHasDropboxFeature)
.alert.alert-info #{translate("dropbox_is_premium")}    
a.btn.btn-info(href='/user/subscription/plans') #{translate("upgrade")}
- if(!user.features.dropbox)
p.small #{translate("dropbox_sync_description")}
.alert.alert-info
p #{translate("dropbox_is_premium")}
p
a.btn.btn-info(href='/user/subscription/plans') #{translate("upgrade")}
- else if(userIsRegisteredWithDropbox)
.alert.alert-success #{translate("account_is_linked")}
row
@ -114,7 +117,7 @@ block content
| !{moduleIncludes("userSettings", locals)}
hr.soften
hr
p.small
| #{translate("newsletter_info_and_unsubscribe")}

View file

@ -198,8 +198,8 @@ describe "ProjectController", ->
first_name: 'James'
'user-2':
first_name: 'Henry'
@users[@user._id] = @user # Owner
@UserModel.findById = (id, fields, callback) =>
fields.should.equal 'first_name last_name'
callback null, @users[id]
@LimitationsManager.userHasSubscriptionOrIsGroupMember.callsArgWith(1, null, false)
@ -224,6 +224,12 @@ describe "ProjectController", ->
done()
@ProjectController.projectListPage @req, @res
it "should send the user", (done)->
@res.render = (pageName, opts)=>
opts.user.should.deep.equal @user
done()
@ProjectController.projectListPage @req, @res
it "should inject the users", (done) ->
@res.render = (pageName, opts)=>
opts.projects[0].owner.should.equal (@users[@projects[0].owner_ref])