Skip to content

Commit

Permalink
Unfix frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
foodelevator committed Aug 31, 2023
1 parent 5c59405 commit 2b27ce3
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 24 deletions.
3 changes: 2 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var api = require('./routes/api');
var kthpeople = require('./routes/kthpeople');
var login = require('./routes/login');
var groups = require('./routes/groups');
var helpers = require('./routes/helpers');

var pug = require("pug");
var babel = require("jade-babel");
Expand Down Expand Up @@ -47,7 +48,7 @@ app.use('/users', users);
app.use('/roles', roles);
app.use('/mandates', mandates);
app.use('/api', api);
app.use('/kthpeople', kthpeople);
app.use('/kthpeople', helpers.requiresearch, kthpeople);
app.use('/login', login);
app.use('/groups', groups);

Expand Down
3 changes: 2 additions & 1 deletion public_scripts/search-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ var SearchBar = React.createClass({
render: function() {
return (
<div >
<input type='text' disabled="disabled" placeholder="Namn" onChange={this.onChange} value={this.state.query} onKeyDown={this.onKey} />
<input type='text' placeholder="Namn" onChange={this.onChange} value={this.state.query} onKeyDown={this.onKey} />
<input type='button' onClick={this.onSubmit} value="Sök"/>
</div>
);
Expand Down Expand Up @@ -184,6 +184,7 @@ var Result = React.createClass({

return (
<div className="result btn btn-default btn-sm btn-block" onClick={callOnSelect} >
<img src={"https://zfinger.datasektionen.se/user/" + this.props.kthid + "/image/128"} />
<h3 className="result-name">
{this.props.fullname}
</h3>
Expand Down
30 changes: 29 additions & 1 deletion routes/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,23 @@ var isadmin = function(user) {
});
};

exports.isadmin = isadmin;
exports.isadmin = isadmin;

var issearch = function(user) {
var plsurl = "https://pls.datasektionen.se/api/user/" + user + "/dfunkt/search";
return new Promise(function (resolve) {
request({uri: plsurl, method: 'GET'}, function (error, response, body) {
if(error) console.error(error);
if (body === "true") {
resolve(true);
} else {
resolve(false);
}
});
});
};

exports.issearch = issearch;

exports.requirelogin = function(req, res, next) {
if(req.user) {
Expand All @@ -43,6 +59,18 @@ exports.requireadmin = function(req, res, next) {
});
};

exports.requiresearch = function(req, res, next) {
issearch(req.user).then(function(search) {
if(search) {
next();
} else {
denied(res);
}
}).catch(function(e) {
console.error(e);
});
};

var roleAtt = ['title', 'description', 'identifier', 'email', 'active', 'id'];
var userAtt = ['first_name', 'last_name', 'email', 'kthid', 'ugkthid'];
var groupAtt = ['name', 'identifier'];
Expand Down
38 changes: 24 additions & 14 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ router.get('/', function(req, res) {
Promise.all([
helpers.rolesFindAllCurrent(),
helpers.isadmin(req.user),
helpers.issearch(req.user),
]).then(function(results) {
var rolemandates = results[0];
console.log(rolemandates);
var isadmin = results[1];
var issearch = results[2];
res.render('index', {
user: req.user,
isadmin: isadmin,
rolemandates: rolemandates,
isadmin,
issearch,
rolemandates,
});
}).catch(function(e) {
console.log(e);
Expand All @@ -36,14 +39,17 @@ router.get('/user/:kthid', function(req, res) {
order: 'start DESC'
}),
helpers.isadmin(req.user),
helpers.issearch(req.user),
]).then(function(results) {
var mandates = results[0];
var isadmin = results[1];
var issearch = results[2];
res.render('user', {
user: req.user,
userobj: user,
isadmin: isadmin,
mandates: mandates,
isadmin,
mandates,
issearch,
});
}).catch(function(e) {
console.log(e);
Expand Down Expand Up @@ -92,11 +98,12 @@ function respondPositionWithRole(role, req, res) {
order: 'start DESC'
});

return Promise.all([ mandatesWithRoleIdP, helpers.isadmin(req.user), models.Group.findAll({}) ])
.spread(function (mandates, isadmin, groups) {
return Promise.all([ mandatesWithRoleIdP, helpers.isadmin(req.user), helpers.issearch(req.user), models.Group.findAll({}) ])
.spread(function (mandates, isadmin, issearch, groups) {
res.render( 'position', {
user: req.user,
isadmin,
issearch,
roleobj: role,
mandates,
groups,
Expand All @@ -121,6 +128,7 @@ router.get('/admin', helpers.requireadmin, function(req, res) {
models.Mandate.findAll({include: [{model: models.User, as: "User"},
{model: models.Role, as: "Role"}]}),
helpers.isadmin(req.user),
helpers.issearch(req.user),
models.Group.findAll({}),
models.User.findAll({
order: 'last_name',
Expand All @@ -131,16 +139,18 @@ router.get('/admin', helpers.requireadmin, function(req, res) {
var roles = results[1];
var mandates = results[2];
var isadmin = results[3];
var groups = results[4];
var admins = results[5];
var issearch = results[4];
var groups = results[5];
var admins = results[6];
res.render('admin', {
user: req.user,
isadmin: isadmin,
users: users,
roles: roles,
mandates: mandates,
groups: groups,
admins: admins,
isadmin,
issearch,
users,
roles,
mandates,
groups,
admins,
});
});
});
Expand Down
5 changes: 4 additions & 1 deletion routes/kthpeople.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ var router = express.Router();
router.get('/', function(req, res) {
Promise.all([
helpers.isadmin(req.user),
helpers.issearch(req.user),
]).then(function(results) {
var isadmin = results[0];
var issearch = results[1];
res.render('kthsearch', {
user: req.user,
isadmin: isadmin,
isadmin,
issearch,
});
});
});
Expand Down
11 changes: 5 additions & 6 deletions views/sidebar.pug
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
div(class='col-sm-4 col-md-3')
div(id='secondary-nav')
h3
#user
#user
if user
p Logged in as #{user}
else
p Dfunkt
ul
li
a(href='/') Hem
li
a(href='/kthpeople') Användar-lookup
#isadmin
if isadmin
ul
if issearch
li
a(href='/kthpeople') Användarsökningsfunktion
if isadmin
li
a(href='/admin') Adminstrativt

0 comments on commit 2b27ce3

Please sign in to comment.