diff --git a/public/app.js b/public/app.js index 88e97a4b..ae9b3a60 100644 --- a/public/app.js +++ b/public/app.js @@ -9,6 +9,8 @@ Ext.application({ var mainTab = Ext.ComponentQuery.query('#mainTabPanel')[0]; if(Ext.util.Cookies.get('role') == "Test Designer"){ mainTab.remove(mainTab.down("#adminTab")); + //dev changes user specific access + //mainTab.remove(mainTab.down("#ScriptBrowser")); mainTab.down("scriptBrowser").down("#compileBar").hide(); mainTab.down("scriptBrowser").down("#saveAll").hide(); mainTab.down("scriptBrowser").down("#push").hide(); @@ -23,7 +25,10 @@ Ext.application({ mainTab.down("actions").down("#deleteAction").hide(); mainTab.down("actions").down("#cloneAction").hide(); mainTab.down("actions").down("#newAction").hide(); - } + //dev changes + } else if(Ext.util.Cookies.get('role') == "Developer") { + mainTab.remove(mainTab.down("#adminTab")); + } //dev changes }, controllers: [ diff --git a/public/model/Users.js b/public/model/Users.js index b836990a..dada02ae 100644 --- a/public/model/Users.js +++ b/public/model/Users.js @@ -29,6 +29,13 @@ Ext.define('Redwood.model.Users', { }, { name: 'status', type: 'string' + }, + //dev changes + { + name: 'projects', + type: 'array' } + //dev changes + ] }); \ No newline at end of file diff --git a/public/view/UserEdit.js b/public/view/UserEdit.js index 9879797c..5fc7b615 100644 --- a/public/view/UserEdit.js +++ b/public/view/UserEdit.js @@ -85,6 +85,9 @@ Ext.define('Redwood.view.UserEdit', { var newUser = {}; newUser.name = form.getFieldValues().name; newUser.tag = form.getFieldValues().tag; + //dev changes + newUser.projects = form.getFieldValues().projects; + //dev changes newUser.password = form.getFieldValues().firstpassword; newUser.username = form.getFieldValues().username; newUser.email = form.getFieldValues().email; @@ -208,7 +211,37 @@ Ext.define('Redwood.view.UserEdit', { } } } - } + }, + //dev changes + { + xtype:"combofieldbox", + afterLabelTextTpl: this.requiredText, + fieldLabel: 'Projects', + displayField:"name", + descField:"name", + height:24, + labelWidth: 100, + forceSelection:false, + createNewOnEnter:false, + encodeSubmitValue:true, + autoSelect: false, + triggerAction: 'all', + store:Ext.data.StoreManager.lookup('Projects'), + valueField:"_id", + queryMode: 'local', + removeOnDblClick:true, + allowBlank: false, + maskRe: /[a-z_0-9_A-Z_-]/, + name:"projects", + listeners: { + specialkey: function(field, e){ + if (e.getKey() == e.ENTER) { + this.up('form').down("#submit").handler(); + } + } + } + } + //dev changes ,{ xtype:'textfield', vtype: 'passwordTest', diff --git a/routes/auth.js b/routes/auth.js index 4263e4fc..2f4f12fe 100644 --- a/routes/auth.js +++ b/routes/auth.js @@ -2,6 +2,7 @@ var sessions = {}; var projects = require('../routes/projects'); var userState = require('../routes/userStates'); var realtime = require("./realtime"); +var common = require('../common'); exports.loginPage = function(req,res){ res.redirect('/login.html'); @@ -22,17 +23,27 @@ exports.loadSessions = function(){ }; exports.logIn = function (req,res,next){ - verifyUser(req.body.username,req.body.password,function(userFound,role){ + verifyUser(req.body.username,req.body.password,function(userFound,user){ + console.log(user); + //common.logger.info("projects",user.projects[0]); if (userFound){ require('crypto').randomBytes(20, function(ex, buf) { realtime.emitMessage("Login",req.body.username); var token = buf.toString('hex'); - sessions[req.body.username] = {sessionid:token,expires:new Date(Date.now() + 2592000000),role:role}; + console.log("role:", user.role); + common.logger.info("login projects", user.projects); + sessions[req.body.username] = {sessionid:token,expires:new Date(Date.now() + 2592000000),role:user.role, userId:user._id, projects:user.projects}; storeSession(req.body.username,token,new Date(Date.now() + 2592000000)); res.cookie('sessionid', token, { expires: new Date(Date.now() + 2592000000), httpOnly: false}); res.cookie('username', req.body.username, {maxAge: 2592000000, httpOnly: false }); - res.cookie('role', role, {maxAge: 2592000000, httpOnly: false }); + res.cookie('role', user.role, {maxAge: 2592000000, httpOnly: false }); + res.cookie('userId', user._id, {maxAge: 2592000000, httpOnly: false }); + if (user.role !== 'Admin') { + res.cookie('projects', user.projects, {maxAge: 2592000000, httpOnly: false }); + res.cookie('userDefaultProject', user.projects[0], {maxAge: 2592000000, httpOnly: false }); + } return next(); + }); } else{ @@ -43,42 +54,65 @@ exports.logIn = function (req,res,next){ function logInSucess(req,res){ userState.GetUserProject(req.cookies.username,function(project){ + console.log("######################################"); + console.log(res); + var roleField = res.get("set-cookie")[2].split(";"); + var userRole = roleField[0].split("=")[1]; + + if(userRole !== 'Admin') { + var projectField = res.get("set-cookie")[5].split(";"); + var defaultProjectID = projectField[0].split("=")[1]; + } + //common.logger.info("cookie projects string", defaultProjectID); + //common.logger.info("cookie userRole string", userRole); + //common.logger.info("cookie projects", res.get("set-cookie")[3].indexOf("=")); + //common.logger.info("cookie projects length", res.get("set-cookie")[3].length); + //common.logger.info("cookie projects typeod", typeof res.get("set-cookie")[3]); + //common.logger.info("user projects", req.cookies.projects[0]); + //common.logger.info("resp project", project); + //common.logger.info("cookie project",req.cookies.project); + //var userDefaultProject = req.cookies.projects[0]; if(req.cookies.deeplink){ + common.logger.info("at if logic"); res.clearCookie('deeplink'); - if(req.originalUrl != "/index.html"){ - res.json({error:null,redirect:req.cookies.deeplink}); - } - else{ - res.json({error:null,redirect:"./index.html"}); - } - } - else if ((project == null) && ((req.cookies.project === undefined)||(req.cookies.project == "") )){ + common.logger.info("resp project", project); projects.allProjects(function(projects){ - res.cookie('project', projects[0].name, {maxAge: 2592000000, httpOnly: false }); - res.redirect("/index.html"); - // res.json({error:null,redirect:"./index.html"}); + if(userRole !== "Admin") { + projects.forEach(function(project){ + common.logger.info("project name if logic", project._id.toString()); + if (project._id.toString() == defaultProjectID){ + res.cookie('project', project.name, {maxAge: 2592000000, httpOnly: false }); + } + }); + } else { + res.cookie('project', projects[0].name, {maxAge: 2592000000, httpOnly: false }); + } + if(req.originalUrl != "/index.html"){ + res.json({error:null,redirect:"./index.html"}); + } + else{ + res.json({error:null,redirect:"./index.html"}); + } }); } - else if (project == null){ + else if ((project == null) || (req.cookies.project === undefined) || (req.cookies.project == "")){ + common.logger.info("at else logic"); projects.allProjects(function(projects){ var found = false; - projects.forEach(function(project){ - if (project.name === req.cookies.project){ - found = true; - } - }); - if (found == false){ + if(userRole !== "Admin") { + projects.forEach(function(project){ + if (project._id.toString() == defaultProjectID){ + found = true; + res.cookie('project', project.name, {maxAge: 2592000000, httpOnly: false }); + } + }); + } else { res.cookie('project', projects[0].name, {maxAge: 2592000000, httpOnly: false }); } + res.json({error:null,redirect:"./index.html"}); }); } - else{ - if ((req.cookies.project === undefined)||(req.cookies.project == "")){ - res.cookie('project', project, {maxAge: 2592000000, httpOnly: false }); - } - res.json({error:null,redirect:"./index.html"}); - } }) } exports.logInSucess = function(req,res){ @@ -86,14 +120,17 @@ exports.logInSucess = function(req,res){ }; exports.auth = function(req,res,next){ + //common.logger.info("Original url", req.originalUrl); if (sessions[req.cookies.username] != undefined){ if (req.cookies.sessionid == sessions[req.cookies.username].sessionid){ if (req.cookies.project == undefined){ if(req.originalUrl == "/index.html"){ + common.logger.info("Original url", req.originalUrl); res.cookie('deeplink', req.originalUrl, {maxAge: 2592000000, httpOnly: false }); return next(); } else{ + common.logger.info("Original url", req.originalUrl); logInSucess(req,res); return; } @@ -139,8 +176,8 @@ function verifyUser(username,password,callback){ callback(false,null); } else{ - callback(true,user.role); + callback(true,user); } }); }) -} \ No newline at end of file +} diff --git a/routes/projects.js b/routes/projects.js index bdbcb90e..915186b5 100644 --- a/routes/projects.js +++ b/routes/projects.js @@ -34,14 +34,38 @@ exports.projectsPut = function(req, res){ exports.projectsGet = function(req, res){ GetProjects(app.getDB(),{},function(data){ + //dev changes + common.logger.info("my projects", req.cookies.projects); + var userProjects = req.cookies.projects, userRole = req.cookies.role, userId = req.cookies.userId, projectCollection = []; + var ObjectID = require('mongodb').ObjectID; + + common.logger.info("userRole:", userRole, "userProjects:", userProjects); + if(userRole !== "Admin") { + for (var i = 0; i < data.length; i++){ + + common.logger.info("Project id:", data[i]._id.toString()); + + common.logger.info("Project exists:", userProjects.indexOf(data[i]._id.toString())); + if(userProjects.indexOf(data[i]._id.toString()) > -1){ + projectCollection.push(data[i]); + } + } + + } else { + projectCollection = data; + } + common.logger.info(projectCollection); + //dev changes + res.contentType('json'); res.json({ success: true, - projects: data + //dev changes + projects: projectCollection }); - }); + }, req); }; - +//dev changes exports.projectsDelete = function(req, res){ var db = app.getDB(); var id = new ObjectID(req.params.id); @@ -360,15 +384,18 @@ function DeleteProjects(db,data,projectName,callback){ */ callback(); } - -function GetProjects(db,query,callback){ +//dev changes +function GetProjects(db,query,callback, req){ + //dev changes var projects = []; db.collection('projects', function(err, collection) { collection.find(query, {}, function(err, cursor) { cursor.each(function(err, project) { if(project == null) { - callback(projects); + //dev changes + callback(projects, req); + //dev changes return; } projects.push(project); diff --git a/routes/users.js b/routes/users.js index ef7bd188..b4340d91 100644 --- a/routes/users.js +++ b/routes/users.js @@ -289,6 +289,7 @@ function UpdateUsers(db,data,callback){ u.name = data.name; u.tag = data.tag; u.email = data.email; + u.projects = data.projects; u._id = data._id; if(data.password){ u.password = data.password;