@@ -22,7 +22,6 @@ var categories = require('../controllers/discussion').categories;
2222
2323var userRoles = require ( '../models/userRoles.json' ) ;
2424var scriptStorage = require ( './scriptStorage' ) ;
25- var RepoManager = require ( '../libs/repoManager' ) ;
2625var modelParser = require ( '../libs/modelParser' ) ;
2726var modelQuery = require ( '../libs/modelQuery' ) ;
2827var flagLib = require ( '../libs/flag' ) ;
@@ -1030,129 +1029,6 @@ var parseJavascriptBlob = function (aJavascriptBlob) {
10301029 return aJavascriptBlob ;
10311030} ;
10321031
1033- // Sloppy code to let a user add scripts to their acount
1034- exports . userManageGitHubPage = function ( aReq , aRes , aNext ) {
1035- var authedUser = aReq . session . user ;
1036-
1037- //
1038- var options = { } ;
1039- var tasks = [ ] ;
1040-
1041- // Session
1042- authedUser = options . authedUser = modelParser . parseUser ( authedUser ) ;
1043- options . isMod = authedUser && authedUser . isMod ;
1044- options . isAdmin = authedUser && authedUser . isAdmin ;
1045-
1046- // Page metadata
1047- pageMetadata ( options , [ 'Manage' , 'GitHub' ] ) ;
1048-
1049- //
1050- tasks . push ( function ( aCallback ) {
1051- var githubUserName = aReq . query . user || authedUser . ghUsername ;
1052-
1053- async . waterfall ( [
1054- // authedUser.ghUsername
1055- function ( aCallback ) {
1056- if ( githubUserName || authedUser . ghUsername ) {
1057- aCallback ( null ) ;
1058- } else {
1059- async . waterfall ( [
1060- function ( aCallback ) {
1061- var githubUserId = authedUser . githubUserId ( ) ;
1062- github . user . getFrom ( {
1063- user : encodeURIComponent ( githubUserId )
1064- } , aCallback ) ;
1065- } ,
1066- function ( aGithubUser , aCallback ) {
1067- options . githubUser = aGithubUser ;
1068- console . log ( aGithubUser ) ;
1069- User . findOne ( {
1070- _id : authedUser . _id
1071- } , aCallback ) ;
1072- } ,
1073- function ( aUserData , aCallback ) {
1074- console . log ( aUserData ) ;
1075- aUserData . ghUsername = options . githubUser . login ;
1076- aUserData . save ( aCallback ) ;
1077- } ,
1078- function ( aCallback ) {
1079- console . log ( util . format ( 'Updated User(%s).ghUsername' , aUserData . name ) ) ;
1080- aCallback ( null ) ;
1081- } ,
1082- ] , aCallback ) ;
1083- }
1084- } ,
1085- // Fetch repos and format for template.
1086- function ( aCallback ) {
1087- console . log ( githubUserName ) ;
1088- var repoManager = RepoManager . getManager ( githubUserName , authedUser ) ;
1089- repoManager . fetchRecentRepos ( function ( ) {
1090- // convert the repos object to something mustache can use
1091- options . repos = repoManager . makeRepoArray ( ) ;
1092-
1093- var repos = repoManager . repos ;
1094- aCallback ( null , repos ) ;
1095- } ) ;
1096- } ,
1097- // Import repos.
1098- function ( aRepos , aCallback ) {
1099- var loadable = { } ;
1100- var scriptname = null ;
1101-
1102- console . log ( aReq . body ) ;
1103- _ . each ( aReq . body , function ( aRepo , aReponame ) {
1104- // Load all scripts in the repo
1105- if ( typeof aRepo === 'string' && aReponame . substr ( - 4 ) === '_all' ) {
1106- aReponame = aRepo ;
1107- aRepo = aRepos [ aReponame ] ;
1108-
1109- if ( aRepo ) {
1110- for ( scriptname in aRepo ) {
1111- if ( ! loadable [ aReponame ] ) { loadable [ aReponame ] = nil ( ) ; }
1112- loadable [ aReponame ] [ scriptname ] = aRepo [ scriptname ] ;
1113- }
1114- }
1115- } else if ( typeof aRepo === 'object' ) { // load individual scripts
1116- for ( scriptname in aRepo ) {
1117- if ( aRepos [ aReponame ] [ scriptname ] ) {
1118- if ( ! loadable [ aReponame ] ) { loadable [ aReponame ] = nil ( ) ; }
1119- loadable [ aReponame ] [ scriptname ] = aRepos [ aReponame ] [ scriptname ] ;
1120- }
1121- }
1122- }
1123- } ) ;
1124-
1125- // Load the scripts onto the site
1126- if ( _ . size ( loadable ) > 0 ) {
1127- console . log ( 'loadScripts' ) ;
1128- var githubUserName = authedUser . ghUsername ;
1129- RepoManager . getManager ( githubUserName , authedUser , loadable ) . loadScripts ( function ( ) {
1130- console . log ( 'preredirect' ) ;
1131- aRes . redirect ( authedUser . userScriptListPageUrl ) ;
1132- console . log ( 'redirect' ) ;
1133- aCallback ( null ) ;
1134- } ) ;
1135- } else {
1136- aCallback ( null ) ;
1137- }
1138- } ,
1139- ] , aCallback ) ;
1140- } ) ;
1141-
1142-
1143- //---
1144- async . parallel ( tasks , function ( aErr ) {
1145- if ( aErr ) {
1146- return statusCodePage ( aReq , aRes , aNext , {
1147- statusMessage : aErr
1148- } ) ;
1149- }
1150-
1151- console . log ( 'render' ) ;
1152- aRes . render ( 'pages/userManageGitHub' , options ) ;
1153- } ) ;
1154- } ;
1155-
11561032exports . uploadScript = function ( aReq , aRes , aNext ) {
11571033 var authedUser = aReq . session . user ;
11581034 var isLib = aReq . params . isLib ;
0 commit comments