ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anovi...@apache.org
Subject incubator-ignite git commit: # ignite-843 Refactor become this user.
Date Mon, 13 Jul 2015 10:34:10 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-843 bd49a5e14 -> 88cfa4eaa


# ignite-843 Refactor become this user.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/88cfa4ea
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/88cfa4ea
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/88cfa4ea

Branch: refs/heads/ignite-843
Commit: 88cfa4eaa71c7a0031944e9e45ad719bc1f29e6b
Parents: bd49a5e
Author: Andrey <anovikov@gridgain.com>
Authored: Mon Jul 13 17:34:43 2015 +0700
Committer: Andrey <anovikov@gridgain.com>
Committed: Mon Jul 13 17:34:43 2015 +0700

----------------------------------------------------------------------
 modules/web-control-center/nodejs/app.js        | 17 +++---
 .../web-control-center/nodejs/routes/admin.js   | 29 ++++-------
 .../web-control-center/nodejs/routes/profile.js |  6 +--
 .../nodejs/views/includes/header.jade           | 21 ++++----
 .../nodejs/views/settings/admin.jade            | 16 +++---
 .../nodejs/views/templates/headers.jade         | 55 --------------------
 .../nodejs/views/templates/layout.jade          | 46 ++++++++++++++--
 7 files changed, 79 insertions(+), 111 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/88cfa4ea/modules/web-control-center/nodejs/app.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/app.js b/modules/web-control-center/nodejs/app.js
index 79e51c7..9fb4398 100644
--- a/modules/web-control-center/nodejs/app.js
+++ b/modules/web-control-center/nodejs/app.js
@@ -103,27 +103,22 @@ for (var p in uiUtils) {
 }
 
 app.all('*', function(req, res, next) {
-    res.locals.user = req.user;
+    var becomeUsed = req.session.viewedUser && req.user.admin;
 
-    res.locals.viewedUser = req.session.viewedUser;
+    res.locals.user = becomeUsed ? req.session.viewedUser : req.user;
+    res.locals.becomeUsed = becomeUsed;
 
     req.currentUserId = function() {
         if (!req.user)
             return null;
 
-        if (req.session.viewedUser) {
-            if (req.user.admin)
-                return req.session.viewedUser._id;
-
-            req.session.viewedUser = null;
-        }
+        if (req.session.viewedUser && req.user.admin)
+            return req.session.viewedUser._id;
 
         return req.user._id;
     };
 
-    res.locals.currentUserId = req.currentUserId;
-
-    next()
+    next();
 });
 
 app.use('/', publicRoutes);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/88cfa4ea/modules/web-control-center/nodejs/routes/admin.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/routes/admin.js b/modules/web-control-center/nodejs/routes/admin.js
index 422f08b..86ea58f 100644
--- a/modules/web-control-center/nodejs/routes/admin.js
+++ b/modules/web-control-center/nodejs/routes/admin.js
@@ -17,7 +17,6 @@
 
 var router = require('express').Router();
 var db = require('../db');
-var uiUtils = require('../helpers/ui-utils');
 
 router.get('/', function(req, res) {
     res.render('settings/admin');
@@ -27,17 +26,11 @@ router.get('/', function(req, res) {
  * Get list of user accounts.
  */
 router.post('/list', function(req, res) {
-    db.Account.find({}, function (err, users) {
+    db.Account.find({}).select('_id username email lastLogin admin').exec(function (err,
users) {
         if (err)
             return res.status(500).send(err.message);
 
-        var uiUsers = [];
-
-        for (var i = 0; i < users.length; i++) {
-            uiUsers.push(uiUtils.filterUser(users[i]))
-        }
-
-        res.json(uiUsers);
+        res.json(users);
     });
 });
 
@@ -45,10 +38,10 @@ router.post('/remove', function(req, res) {
     var userId = req.body.userId;
 
     db.Account.findByIdAndRemove(userId, function(err) {
-        if (!err)
-            res.sendStatus(200);
-        else
-            res.status(500).send(err);
+        if (err)
+            return res.status(500).send(err);
+
+        res.sendStatus(200);
     });
 });
 
@@ -57,10 +50,10 @@ router.post('/save', function(req, res) {
     var adminFlag = req.body.adminFlag;
 
     db.Account.findByIdAndUpdate(userId, {admin: adminFlag}, function(err) {
-        if (!err)
-            res.sendStatus(200);
-        else
-            res.status(500).send(err);
+        if (err)
+            return res.status(500).send(err.message);
+
+        res.sendStatus(200);
     });
 });
 
@@ -79,7 +72,7 @@ router.get('/become', function(req, res) {
         if (err)
             return res.sendStatus(404);
 
-        req.session.viewedUser = {_id: viewedUser._id, username: viewedUser.username};
+        req.session.viewedUser = viewedUser;
 
         res.redirect('/');
     })

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/88cfa4ea/modules/web-control-center/nodejs/routes/profile.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/routes/profile.js b/modules/web-control-center/nodejs/routes/profile.js
index 015b07c..5caae0b 100644
--- a/modules/web-control-center/nodejs/routes/profile.js
+++ b/modules/web-control-center/nodejs/routes/profile.js
@@ -60,7 +60,7 @@ router.post('/saveUser', function (req, res) {
 
             user.setPassword(newPassword, function (err, updatedUser) {
                 if (err)
-                    return res.status(500).send(err);
+                    return res.status(500).send(err.message);
 
                 if (params.userName)
                     updatedUser.username = params.userName;
@@ -70,7 +70,7 @@ router.post('/saveUser', function (req, res) {
 
                 updatedUser.save(function (err) {
                     if (err)
-                        return res.status(500).send(err);
+                        return res.status(500).send(err.message);
 
                     res.json(uiUtils.filterUser(user));
                 });
@@ -88,7 +88,7 @@ router.post('/saveUser', function (req, res) {
 
         db.Account.findByIdAndUpdate(params._id, upd, {new: true}, function (err, val) {
             if (err)
-                return res.status(500).send(err);
+                return res.status(500).send(err.message);
 
             res.json(uiUtils.filterUser(val));
         })

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/88cfa4ea/modules/web-control-center/nodejs/views/includes/header.jade
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/views/includes/header.jade b/modules/web-control-center/nodejs/views/includes/header.jade
index 1a6c1ad..5f29415 100644
--- a/modules/web-control-center/nodejs/views/includes/header.jade
+++ b/modules/web-control-center/nodejs/views/includes/header.jade
@@ -18,31 +18,30 @@ mixin header-item(active, ref, txt)
         a(ng-class='{active: isActive("#{active}")}' href='#{ref}') #{txt}
 
 header.header(id='header')
+    div.viewedUser(ng-show='becomeUsed') You're working as&nbsp;
+        strong {{user.username}}&nbsp;
+        a(href='/admin/become')
+            span.fa.fa-remove(title='Unlogin')
     .container
         h1.navbar-brand
             a(href='/') Apache Ignite Web Configurator
         .navbar-collapse.collapse(ng-controller='auth')
-            ul.nav.navbar-nav(ng-controller='activeLink' ng-show='loggedInUser')
+            ul.nav.navbar-nav(ng-controller='activeLink')
                 +header-item('/configuration', '/configuration/clusters', 'Configuration')
                 //+header-item('/monitoring', '/monitoring', 'Monitoring')
                 //+header-item('/sql', '/sql', 'SQL')
                 //+header-item('/deploy', '/deploy', 'Deploy')
             ul.nav.navbar-nav.pull-right
-                li(ng-show='loggedInUser')
-                    a.dropdown-toggle(data-toggle='dropdown' aria-expanded='true' bs-dropdown
data-template='user-dropdown' data-placement='bottom-right') {{loggedInUser.username}}
+                li(ng-show='user')
+                    a.dropdown-toggle(data-toggle='dropdown' aria-expanded='true' bs-dropdown
data-template='user-dropdown' data-placement='bottom-right') {{user.username}}
                         span.caret
                     script#user-dropdown(type='text/ng-template')
                         ul.dropdown-menu
                             li
                                 a(href='/profile') Profile
-                            li(ng-if='loggedInUser && loggedInUser.admin')
+                            li(ng-if='user.admin')
                                 a(href='/admin') Admin Panel
                             li
                                 a(href='/logout') Log Out
-                li.nav-login(ng-show='!loggedInUser')
-                    a(ng-click='login()' href='#') Log In
-
-        div(class='viewedUser' ng-show='viewedUser') You're working as&nbsp;
-            strong {{viewedUser.username}}&nbsp;
-            a(href='/admin/become')
-                span(class="glyphicon glyphicon-remove" title='Unlogin')
+                li.nav-login(ng-show='!user')
+                    a(ng-click='login()' href='#') Log In
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/88cfa4ea/modules/web-control-center/nodejs/views/settings/admin.jade
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/views/settings/admin.jade b/modules/web-control-center/nodejs/views/settings/admin.jade
index 2bceab5..3205c8f 100644
--- a/modules/web-control-center/nodejs/views/settings/admin.jade
+++ b/modules/web-control-center/nodejs/views/settings/admin.jade
@@ -37,17 +37,17 @@ block container
                             th(width='1%'  st-sort='admin') Admin
                             th(width='1%') Actions
                     tbody
-                        tr(ng-repeat='user in displayedUsers')
-                            td {{user.username}}
+                        tr(ng-repeat='row in displayedUsers')
+                            td {{row.username}}
                             td
-                                a(ng-href='mailto:{{user.email}}') {{user.email}}
+                                a(ng-href='mailto:{{row.email}}') {{row.email}}
                             td
-                                span {{user.lastLogin | date:'medium'}}
+                                span {{row.lastLogin | date:'medium'}}
                             td(style='text-align: center;')
-                                input(type='checkbox' ng-disabled='user.adminChanging ||
user._id == loggedInUser._id'
-                                    ng-model='user.admin' ng-change='toggleAdmin(user)')
+                                input(type='checkbox' ng-disabled='row.adminChanging || row._id
== user._id'
+                                    ng-model='row.admin' ng-change='toggleAdmin(user)')
                             td(style='text-align: center;')
-                                a(ng-click='removeUser(user)' ng-show='user._id != loggedInUser._id'
title='Remove user')
+                                a(ng-click='removeUser(row)' ng-show='row._id != user._id'
title='Remove user')
                                     i.fa.fa-remove
-                                a(style='margin-left: 5px' ng-href='admin/become?viewedUserId={{user._id}}'
ng-show='user._id != loggedInUser._id' title='View user\'s configurations')
+                                a(style='margin-left: 5px' ng-href='admin/become?viewedUserId={{row._id}}'
ng-show='row._id != user._id' title='View user\'s configurations')
                                     i.fa.fa-eye

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/88cfa4ea/modules/web-control-center/nodejs/views/templates/headers.jade
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/views/templates/headers.jade b/modules/web-control-center/nodejs/views/templates/headers.jade
deleted file mode 100644
index c70f9d1..0000000
--- a/modules/web-control-center/nodejs/views/templates/headers.jade
+++ /dev/null
@@ -1,55 +0,0 @@
-//-
-    Licensed to the Apache Software Foundation (ASF) under one or more
-    contributor license agreements.  See the NOTICE file distributed with
-    this work for additional information regarding copyright ownership.
-    The ASF licenses this file to You under the Apache License, Version 2.0
-    (the "License"); you may not use this file except in compliance with
-    the License.  You may obtain a copy of the License at
-
-         http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
-
-doctype html
-html(ng-app='ignite-web-control-center', ng-init='loggedInUser = #{JSON.stringify(filterUser(user))};
viewedUser = #{JSON.stringify(viewedUser)}')
-    head
-        title= title
-
-        block css
-            // Bootstrap
-            link(rel='stylesheet', href='//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.css')
-
-            // Font Awesome Icons
-            link(rel='stylesheet', href='//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.css')
-
-            // Font
-            link(rel='stylesheet', href='//fonts.googleapis.com/css?family=Roboto+Slab:700:serif|Roboto+Slab:400:serif')
-
-            link(rel='stylesheet', href='/stylesheets/style.css')
-
-        block scripts
-            script(src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js')
-
-            script(src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.0/lodash.min.js')
-
-            script(src='//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js')
-            script(src='//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-sanitize.js')
-            script(src='//cdnjs.cloudflare.com/ajax/libs/angular-strap/2.2.2/angular-strap.js')
-            script(src='//cdnjs.cloudflare.com/ajax/libs/angular-strap/2.2.2/angular-strap.tpl.min.js')
-
-            script(src='https://cdnjs.cloudflare.com/ajax/libs/angular-smart-table/2.0.3/smart-table.js')
-
-            script(src='/common-module.js')
-            script(src='/data-structures.js')
-
-    body.theme-line.body-overlap
-        .wrapper
-            include ../includes/header
-
-            block main-container
-
-            include ../includes/footer

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/88cfa4ea/modules/web-control-center/nodejs/views/templates/layout.jade
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/views/templates/layout.jade b/modules/web-control-center/nodejs/views/templates/layout.jade
index 17f8da1..e7adc8c 100644
--- a/modules/web-control-center/nodejs/views/templates/layout.jade
+++ b/modules/web-control-center/nodejs/views/templates/layout.jade
@@ -14,9 +14,45 @@
     See the License for the specific language governing permissions and
     limitations under the License.
 
-extends headers
+doctype html
+html(ng-app='ignite-web-control-center', ng-init='user = #{JSON.stringify(filterUser(user))};
becomeUsed = #{becomeUsed}')
+    head
+        title= title
 
-block main-container
-    .container.body-container
-        .main-content
-            block container
+        block css
+            // Bootstrap
+            link(rel='stylesheet', href='//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.css')
+
+            // Font Awesome Icons
+            link(rel='stylesheet', href='//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.css')
+
+            // Font
+            link(rel='stylesheet', href='//fonts.googleapis.com/css?family=Roboto+Slab:700:serif|Roboto+Slab:400:serif')
+
+            link(rel='stylesheet', href='/stylesheets/style.css')
+
+        block scripts
+            script(src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js')
+
+            script(src='//cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.0/lodash.min.js')
+
+            script(src='//ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js')
+            script(src='//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-sanitize.js')
+            script(src='//cdnjs.cloudflare.com/ajax/libs/angular-strap/2.2.2/angular-strap.js')
+            script(src='//cdnjs.cloudflare.com/ajax/libs/angular-strap/2.2.2/angular-strap.tpl.min.js')
+
+            script(src='https://cdnjs.cloudflare.com/ajax/libs/angular-smart-table/2.0.3/smart-table.js')
+
+            script(src='/common-module.js')
+            script(src='/data-structures.js')
+
+    body.theme-line.body-overlap
+        .wrapper
+            include ../includes/header
+
+            block main-container
+                .container.body-container
+                    .main-content
+                        block container
+
+            include ../includes/footer


Mime
View raw message