Commit fb0cb130 authored by matthias.lang's avatar matthias.lang
Browse files

web: distinguish between public search and (Shibboleth-)logged-in users

- don't show "visibility" attributes and filters in public search
- don't show "server certificate" filter in public search
- add login button
- count each number of results that match a filter (not yet shown in UI)
parent 08d21e6d
......@@ -135,17 +135,28 @@
<div class="row">
<div class="ten columns">
<span v-for="category in filterShow" class="one-third column">
<strong>{{ category.name }}:</strong><br/>
<span v-for="filter in category.filters">
<span @click="filter.buttonState = !filter.buttonState"
class="icon fa"
:title="filter.displayName"
v-bind:class="[filter.displayIcon, { 'icon-active': filter.buttonState }]"
style="margin: 5px"
/>
<span v-for="category in filterShow" class="one-third column" v-if="!category.hideInPublicSearch || visitorLoggedIn">
<strong>{{ category.name }}:</strong><br/>
<span v-for="filter in category.filters" v-if="!filter.hideInPublicSearch || visitorLoggedIn">
<span @click="filter.buttonState = !filter.buttonState"
class="icon fa"
:title="filter.displayName"
v-bind:class="[filter.displayIcon, { 'icon-active': filter.buttonState }]"
style="margin: 5px"
>
<!-- <small>{{ filter.resultCount}}</small> -->
</span>
</span>
</span>
</span>
</div>
<div class="two columns">
<div class="row">
<div class="twelve columns" style="text-align: right;">
<span class="button" type="submit" @click="getShibSessionData()" v-if="visitorLoggedIn" required>Hallo, {{ visitorGivenName }} {{ visitorSn }}</span>
<a :href="'/Shibboleth.sso/Login?target=/?q=' + query"><span class="button" v-if="!visitorLoggedIn" required>Nicht eingeloggt</span></a>
</div>
</div>
</div>
</div>
......@@ -162,7 +173,9 @@
<table class="u-full-width" v-if="filteredData.length">
<thead>
<tr>
<th />
<th v-for="entry in tableHeaders"
v-if="!entry.hideInPublicSearch || visitorLoggedIn"
@click="sortBy(entry.field)"
:class="{ active: sortKey == entry.field }">
{{ entry.description }}
......@@ -173,11 +186,15 @@
</thead>
<tbody>
<tr v-for="entry in filteredData" style="vertical-align: top">
<td style="text-align: right">
<a :href="'https://api.ca.kit.edu/redirect/getcert/' + entry.serial">
<i class="fa fa-download" title="Download"></i>
</a>
<i class="fa fa-info-circle" aria-hidden="true"></i>
</td>
<td>
{{entry.cn}} <span v-if="entry.ou">({{entry.ou}})</span></b><br/>
<a v-bind:href="'https://api.ca.kit.edu/redirect/getcert/' + entry.serial">
<small>S/N: {{entry.serial}}</small>
</a>
<small>S/N: {{entry.serial}}</small>
</td>
<td>
<span v-for="email in entry.emailaddresses">{{email}} </span> <!-- TODO: -->
......@@ -198,7 +215,7 @@
<i v-if="entry.type=='Unbekannt'" class="fa fa-question-circle" :title="entry.type"></i>
<i v-if="entry.type=='Server'" class="fa fa-server" :title="entry.type"></i>
</td>
<td>
<td v-if="visitorLoggedIn">
<i v-if="entry.public=='public'" class="fa fa-eye" :title="entry.public"></i>
<i v-if="entry.public=='private'" class="fa fa-eye-slash" :title="entry.public"></i>
<i v-if="entry.public=='unknown'" class="fa fa-low-vision" :title="entry.public"></i>
......@@ -207,15 +224,6 @@
</tbody>
</table>
<!--
<div class="row">
<div class="twelve columns">
<button class="button" type="submit" @click="getShibSessionData()" v-if="visitorLoggedIn" required>Shibbed, {{ visitorName }}</button>
<button class="button" type="submit" @click="getShibSessionData()" v-if="!visitorLoggedIn" required>NOT shibbed</button>
</div>
</div> -->
</div>
</div>
......@@ -231,7 +239,7 @@
{'field': 'notafterepoch', 'description': 'Ablaufdatum'},
{'field': 'valid', 'description': ''},
{'field': 'type', 'description': ''},
{'field': 'public', 'description': ''},
{'field': 'public', 'description': '', 'hideInPublicSearch': true},
],
resultData: [],
loading: false,
......@@ -240,8 +248,9 @@
sortKey: String,
sortOrders: {},
visitorLoggedIn: false,
visitorName: null,
visitorEmail: null,
visitorGivenName: null,
visitorSn: null,
visitorMail: null,
filterShow: {
'validity': {
'name': 'Gültigkeit',
......@@ -250,20 +259,23 @@
'displayName': 'gültig',
'displayIcon': 'fa-check',
filterfunction: function(element) {return element.valid != 'valid' },
'buttonState': true
'buttonState': true,
'resultCount': 0
},
'v_expired': {
'displayName': 'abgelaufen',
'displayIcon': 'fa-times',
filterfunction: function(element) {return element.valid != 'expired' },
'buttonState': false
'buttonState': false,
'resultCount': 0
},
'v_revoked': {
'displayName': 'gesperrt',
'displayIcon': 'fa-ban',
filterfunction: function(element) {return element.valid != 'revoked' },
'buttonState': false
}
'buttonState': false,
'resultCount': 0
}
}
},
'types': {
......@@ -273,47 +285,57 @@
'displayName': 'Nutzer',
'displayIcon': 'fa-user',
filterfunction: function(element) {return element.type != 'Benutzer' },
'buttonState': true
'buttonState': true,
'resultCount': 0
},
't_pseudonym': {
'displayName': 'PN',
'displayIcon': 'fa-user-secret',
filterfunction: function(element) {return element.type != 'Pseudonym' },
'buttonState': true
'buttonState': true,
'resultCount': 0
},
't_group': {
'displayName': 'Gruppe',
'displayIcon': 'fa-users',
filterfunction: function(element) {return element.type != 'Gruppe' },
'buttonState': true
'buttonState': true,
'resultCount': 0
},
't_extern': {
'displayName': 'Extern',
'displayIcon': 'fa-user-plus',
filterfunction: function(element) {return element.type != 'Extern' },
'buttonState': false
'buttonState': false,
'resultCount': 0
},
't_server': {
'displayName': 'Server',
'displayIcon': 'fa-server',
'hideInPublicSearch': true,
filterfunction: function(element) {return element.type != 'Server' },
'buttonState': false
} }
'buttonState': false,
'resultCount': 0
}
}
},
'visibility': {
'name': 'Veröffentlicht',
'hideInPublicSearch': true,
'filters': {
'vis_public': {
'displayName': 'öffentlich',
'displayIcon': 'fa-eye',
filterfunction: function(element) {return element.public != 'public' },
'buttonState': true
'buttonState': true,
'resultCount': 0
},
'vis_private': {
'displayName': 'nicht-öffentlich',
'displayIcon': 'fa-eye-slash',
filterfunction: function(element) {return element.public == 'public' },
'buttonState': true
'buttonState': true,
'resultCount': 0
}
}
}
......@@ -359,7 +381,11 @@
// Let the UI know we're busy
this.loading = true;
url = location.protocol + '//' + location.host + '/pubsearch/v1/json?q=';
if (this.visitorLoggedIn) {
url = location.protocol + '//' + location.host + '/search/v1/json?q=';
} else {
url = location.protocol + '//' + location.host + '/pubsearch/v1/json?q=';
}
// Query our API
this.$http.get(url + encodeURIComponent(this.query)).then(
......@@ -368,9 +394,37 @@
// Let the UI know we're done
this.loading = false;
//this.query = '';
// bin search results
this.resultData.forEach(
function(entry) {
for (var filterCategory in this.filterShow) {
for (var elem in this.filterShow[filterCategory].filters) {
var filter = this.filterShow[filterCategory].filters[elem]
if (!filter.filterfunction(entry)) {
filter.resultCount++;
}
}
}
}, this
)
for (var filterCategory in this.filterShow) {
for (var elem in this.filterShow[filterCategory].filters) {
this.filterShow[filterCategory].filters[elem].buttonState = true
}
}
// ---------
}
);
// TODO: error handling
},
// provisorium. TODO: replace with URLSearchParams polyfill or VueRouter
......@@ -381,30 +435,50 @@
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
},
/*
getShibSessionData: function() {
url = location.protocol + '//' + location.host + '/dumpreq';
this.$http.get(url).then((response) => { // success callback
getShibSessionData: function() {
url = location.protocol + '//' + location.host + '/Shibboleth.sso/Session';
function extractValue(fieldname) {
var re = new RegExp(fieldname + ": (.*)")
var match = re.exec(response.body)
if (match)
return match[1]
else
return null
}
this.visitorLoggedIn = extractValue("Shib-Authentication-Instant") != null;
// Query our API
this.$http.get(url).then(
function(response) {
var res = JSON.parse(response.body); //TODO
if (res.hasOwnProperty('expiration') && res.hasOwnProperty('attributes')) {
this.visitorLoggedIn = true;
res.attributes.forEach(
function(item) {
switch (item.name) {
case 'givenName':
this.visitorGivenName = item.values[0];
break;
case 'sn':
this.visitorSn = item.values[0];
break;
case 'mail':
this.visitorMail = item.values[0];
break;
}
}, this
);
if (this.query == '') {
this.query = this.visitorMail;
this.search();
}
} else {
this.visitorLoggedIn = false;
}
},
function(response) {
// handle error
if (this.visitorLoggedIn) {
this.visitorName = extractValue("Givenname") + " " + extractValue("Sn");
this.visitorEmail = extractValue("Mail");
this.query = this.visitorEmail;
console.log('error')
}
);
/*
}, response => { // error callback
if (response.status == 401) {
this.visitorLoggedIn = false;
......@@ -413,9 +487,8 @@
} else {
this.error = "Couldn't figure out whether or not you're logged in. Will assume that you're not."
}
});
*/
},
*/
sortBy: function (key) {
this.sortKey = key
......@@ -430,7 +503,7 @@
});
this.sortOrders = sortOrders;
//this.getShibSessionData();
this.getShibSessionData();
if (this.getUrlParameter('filter') == 'none') {
// disable all filters
......@@ -441,7 +514,7 @@
}
}
this.query = this.getUrlParameter('q')
if (this.query) {
if (this.query != '') {
this.search()
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment