You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by se...@apache.org on 2015/07/07 10:35:57 UTC

incubator-ignite git commit: IGNITE-843 Add admin page.

Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-843 d62336dd6 -> 073c40fa5


IGNITE-843 Add admin page.


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

Branch: refs/heads/ignite-843
Commit: 073c40fa52436dd74a526771918ea165df5412c2
Parents: d62336d
Author: sevdokimov <se...@jetbrains.com>
Authored: Tue Jul 7 11:35:51 2015 +0300
Committer: sevdokimov <se...@jetbrains.com>
Committed: Tue Jul 7 11:35:51 2015 +0300

----------------------------------------------------------------------
 modules/web-control-center/nodejs/app.js        | 13 ++++
 modules/web-control-center/nodejs/db.js         |  3 +-
 .../javascripts/controllers/adminController.js  | 66 ++++++++++++++++++++
 .../web-control-center/nodejs/routes/admin.js   | 61 ++++++++++++++++++
 .../nodejs/views/admin/userList.jade            | 21 +++++++
 .../nodejs/views/admin/userList_content.html    | 53 ++++++++++++++++
 .../nodejs/views/includes/header.jade           |  2 +
 7 files changed, 218 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/073c40fa/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 81ff42b..226ccda 100644
--- a/modules/web-control-center/nodejs/app.js
+++ b/modules/web-control-center/nodejs/app.js
@@ -31,6 +31,7 @@ var cachesRouter = require('./routes/caches');
 var persistencesRouter = require('./routes/persistences');
 var authRouter = require('./routes/auth');
 var configGenerator = require('./routes/configGenerator');
+var adminRouter = require('./routes/admin');
 
 var passport = require('passport');
 
@@ -83,10 +84,19 @@ var mustAuthenticated = function (req, res, next) {
     req.isAuthenticated() ? next() : res.redirect('/');
 };
 
+var adminOnly = function(req, res, next) {
+    if (!req.isAuthenticated() || !req.user.admin)
+        res.sendStatus(403);
+    else
+        next();
+};
+
 app.all('/configuration/clusters', mustAuthenticated);
 app.all('/configuration/caches', mustAuthenticated);
 app.all('/configuration/summary', mustAuthenticated);
 
+app.all('/admin/*', mustAuthenticated, adminOnly);
+
 app.use('/', pageRoutes);
 app.use('/rest/clusters', clustersRouter);
 app.use('/rest/caches', cachesRouter);
@@ -94,6 +104,9 @@ app.use('/rest/persistences', persistencesRouter);
 app.use('/rest/auth', authRouter);
 app.use('/rest/configGenerator', configGenerator);
 
+app.use('/admin', adminRouter);
+
+
 // Catch 404 and forward to error handler.
 app.use(function (req, res, next) {
     var err = new Error('Not Found');

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/073c40fa/modules/web-control-center/nodejs/db.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/db.js b/modules/web-control-center/nodejs/db.js
index 2dc2be2..da65c51 100644
--- a/modules/web-control-center/nodejs/db.js
+++ b/modules/web-control-center/nodejs/db.js
@@ -29,7 +29,8 @@ mongoose.connect(config.get('mongoDB:url'), {server: {poolSize: 4}});
 // Define account model.
 var AccountSchema = new Schema({
     username: String,
-    lastLogin: Date
+    lastLogin: Date,
+    admin: Boolean
 });
 
 AccountSchema.plugin(passportLocalMongoose, {usernameField: 'email', limitAttempts: true, lastLoginField: 'lastLogin', usernameLowerCase: true});

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/073c40fa/modules/web-control-center/nodejs/public/javascripts/controllers/adminController.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/public/javascripts/controllers/adminController.js b/modules/web-control-center/nodejs/public/javascripts/controllers/adminController.js
new file mode 100644
index 0000000..908b092
--- /dev/null
+++ b/modules/web-control-center/nodejs/public/javascripts/controllers/adminController.js
@@ -0,0 +1,66 @@
+/*
+ * 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.
+ */
+
+configuratorModule.controller('adminController', [
+    '$scope', '$alert', '$http', 'commonFunctions', function ($scope,
+        $alert, $http, commonFunctions) {
+
+        $scope.userList = null;
+
+        function reload() {
+            $http.get('ajax/list')
+                .success(function (data) {
+                    $scope.userList = data;
+                })
+                .error(function (errMsg) {
+                    $alert({title: $scope.errorMessage(errMsg)});
+                });
+        }
+
+        reload();
+
+        $scope.removeUser = function (user) {
+            if (!confirm("You are going to delete user " + user.username + ". Please, confirm it."))
+                return false;
+
+            $http.get('ajax/remove', {params: {userId: user._id}}).success(
+                function (data) {
+                    $scope.alertStr = "User has been removed: " + user.username;
+                    $scope.alertType = 'success';
+
+                    reload();
+                }).error(function (err) {
+                    $scope.alertStr = "Failed to remove user: " + err;
+                });
+
+            return false;
+        };
+        
+        $scope.toggleAdmin = function(user) {
+            if (user.adminChanging)
+                return;
+            
+            user.adminChanging = true;
+
+            $http.get('ajax/setAdmin', {params: {userId: user._id, adminFlag: user.admin}}).success(
+                function (data) {
+                    reload();
+                }).error(function (err) {
+                    $scope.alertStr = "Failed to update user: " + err;
+                });
+        }
+    }]);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/073c40fa/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
new file mode 100644
index 0000000..6ec2ac7
--- /dev/null
+++ b/modules/web-control-center/nodejs/routes/admin.js
@@ -0,0 +1,61 @@
+/*
+ * 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.
+ */
+
+var router = require('express').Router();
+var db = require('../db');
+
+/**
+ * Get list of user accounts.
+ */
+router.get('/ajax/list', function(req, res) {
+    db.Account.find({}, function (err, users) {
+        if (err)
+            return res.status(500).send(err.message);
+        
+        res.json(users);
+    });
+});
+
+router.get('/ajax/remove', function(req, res) {
+    var userId = req.query.userId;
+
+    db.Account.findByIdAndRemove(userId, function(err) {
+        if (!err)
+            res.sendStatus(200);
+        else
+            res.status(500).send(err);
+    });
+});
+
+router.get('/ajax/setAdmin', function(req, res) {
+    var userId = req.query.userId;
+    var adminFlag = req.query.adminFlag;
+
+    db.Account.findByIdAndUpdate(userId, {admin: adminFlag}, function(err) {
+        if (!err)
+            res.sendStatus(200);
+        else
+            res.status(500).send(err);
+    });
+});
+
+router.get('/userList', function(req, res) {
+    res.render('admin/userList', { user: req.user });
+});
+
+
+module.exports = router;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/073c40fa/modules/web-control-center/nodejs/views/admin/userList.jade
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/views/admin/userList.jade b/modules/web-control-center/nodejs/views/admin/userList.jade
new file mode 100644
index 0000000..af2dbd4
--- /dev/null
+++ b/modules/web-control-center/nodejs/views/admin/userList.jade
@@ -0,0 +1,21 @@
+//-
+    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.
+extends ../layout
+
+append scripts
+    script(src='/javascripts/controllers/adminController.js')
+    script(src='//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js')
+
+block container
+    include userList_content.html

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/073c40fa/modules/web-control-center/nodejs/views/admin/userList_content.html
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/views/admin/userList_content.html b/modules/web-control-center/nodejs/views/admin/userList_content.html
new file mode 100644
index 0000000..595891c
--- /dev/null
+++ b/modules/web-control-center/nodejs/views/admin/userList_content.html
@@ -0,0 +1,53 @@
+<div class="row" ng-controller="adminController">
+    <div class="docs-content">
+        <div class="docs-header">
+            <h1>Users</h1>
+            <p>List of registered users</p>
+            <hr>
+        </div>
+        <div class="docs-body">
+            <div ng-class="{alert: true, 'alert-danger': alertType == danger, 'alert-success': alertType == 'success'}"
+                 ng-show="alertStr">
+                {{alertStr}}
+            </div>
+            
+            <table class="table table-striped" st-table="userListDisplay" st-safe-src="userList">
+                <thead>
+                <tr>
+                    <th colspan="5"><input st-search="" class="form-control" placeholder="Search ..." type="text"/></th>
+                </tr>
+                <tr>
+                    <th st-sort="username">User name</th>
+                    <th st-sort="email">Email</th>
+                    <th st-sort="lastLogin">Last login</th>
+                    <th st-sort="lastLogin">Admin</th>
+                    <th>Actions</th>
+                </tr>
+                </thead>
+                <tbody>
+                <tr ng-repeat="user in userListDisplay">
+                    <td>{{user.username}}</td>
+                    <td><a ng-href="mailto:{{user.email}}">{{user.email}}</a></td>
+                    <td>
+                        <span class="small">{{user.lastLogin | date:'medium'}}</span>
+                    </td>
+                    <td>
+                        <input type="checkbox" ng-disabled="user.adminChanging" ng-model="user.admin" 
+                               ng-change="toggleAdmin(user)">
+                    </td>
+                    <td>
+                        <a href ng-click="removeUser(user)" title="Remove user">
+                            <span class="glyphicon glyphicon-remove" style="color: red"></span>
+                        </a>
+                        
+                        <a ng-href="../clusters" title="View user's configurations">
+                            <span class="glyphicon glyphicon-eye-open"></span>
+                        </a>
+                    </td>
+                </tr>
+                </tbody>
+            </table>
+        </div>
+    </div>
+</div>
+

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/073c40fa/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 4176ffd..c8e6deb 100644
--- a/modules/web-control-center/nodejs/views/includes/header.jade
+++ b/modules/web-control-center/nodejs/views/includes/header.jade
@@ -22,6 +22,8 @@ header.header(id='header')
             ul.nav.navbar-nav(ng-controller='activeLink' ng-show='user')
                 li
                     a(ng-class="{active: isActive('/configuration')}" href='/configuration/clusters') Configuration
+                li(ng-show='user && user.admin')
+                    a(ng-class="{active: isActive('/admin')}" href='/admin/userList') Administration
                 //li
                 //    a(ng-class="{active: isActive('/sql')}" href='/sql') SQL
             ul.nav.navbar-nav.pull-right