@@ -123,6 +123,38 @@ module.exports = [
123123 orgs : function ( fetchWhitelistedOrgs ) {
124124 return fetchWhitelistedOrgs ( ) ;
125125 } ,
126+ activeOrg : function (
127+ $stateParams ,
128+ whitelists ,
129+ moment
130+ ) {
131+ var lowerAccountName = $stateParams . userName . toLowerCase ( ) ;
132+ var activeOrg = whitelists . find ( function ( whitelist ) {
133+ return whitelist . attrs . lowerName === lowerAccountName ;
134+ } ) ;
135+ // All of this should be moved to inside @runnable /api-client
136+ activeOrg . attrs . trialEnd = moment ( ) . add ( 2 , 'days' ) . toISOString ( ) ;
137+ activeOrg . attrs . activePeriodEnd = moment ( ) . subtract ( 1 , 'days' ) . toISOString ( ) ;
138+ activeOrg . attrs . gracePeriodEnd = moment ( ) . add ( 5 , 'days' ) . toISOString ( ) ;
139+ activeOrg . attrs . stripeCustomerId = 1234 ;
140+ activeOrg . attrs . hasPaymentMethod = false ;
141+ activeOrg . isInTrial = function ( ) {
142+ return moment ( activeOrg . attrs . trialEnd ) > moment ( ) . utc ( ) ;
143+ } ;
144+ activeOrg . isInGrace = function ( ) {
145+ return ! activeOrg . isInTrial ( ) && moment ( activeOrg . attrs . gracePeriodEnd ) > moment ( ) . utc ( ) ;
146+ } ;
147+ activeOrg . isInActivePeriod = function ( ) {
148+ return moment ( activeOrg . attrs . activePeriodEnd ) > moment ( ) . utc ( ) ;
149+ } ;
150+ activeOrg . isGraceExpired = function ( ) {
151+ return ! activeOrg . isInTrial ( ) && moment . utc ( activeOrg . attrs . gracePeriodEnd ) < moment ( ) . utc ( ) ;
152+ } ;
153+ activeOrg . trialDaysRemaining = function ( ) {
154+ return moment ( activeOrg . attrs . trialEnd ) . diff ( moment . utc ( ) , 'days' ) ;
155+ } ;
156+ return activeOrg ;
157+ } ,
126158 activeAccount : function (
127159 $q ,
128160 $stateParams ,
@@ -131,7 +163,8 @@ module.exports = [
131163 whitelists ,
132164 $timeout ,
133165 user ,
134- eventTracking
166+ eventTracking ,
167+ activeOrg
135168 ) {
136169 var lowerAccountName = $stateParams . userName . toLowerCase ( ) ;
137170 var userName = user . oauthName ( ) . toLowerCase ( ) ;
@@ -151,10 +184,7 @@ module.exports = [
151184 return $q . reject ( new Error ( 'User Unauthorized for Organization' ) ) ;
152185 } ) ;
153186 }
154- var foundWhitelist = whitelists . find ( function ( whitelist ) {
155- return whitelist . attrs . lowerName === lowerAccountName ;
156- } ) ;
157- if ( ! foundWhitelist . attrs . allowed ) {
187+ if ( ! activeOrg . attrs . allowed ) {
158188 // There is a bug in ui-router and a timeout is the workaround
159189 return $timeout ( function ( ) {
160190 $state . go ( 'paused' ) ;
@@ -163,6 +193,14 @@ module.exports = [
163193 }
164194 eventTracking . boot ( user , { orgName : $stateParams . userName } ) ;
165195 return matchedOrg ;
196+ } ,
197+ populateCurrentOrgService : function (
198+ activeOrg ,
199+ activeAccount ,
200+ currentOrg
201+ ) {
202+ currentOrg . poppa = activeOrg ;
203+ currentOrg . github = activeAccount ;
166204 }
167205 }
168206 } , {
0 commit comments