Skip to content

Commit

Permalink
#23088
Browse files Browse the repository at this point in the history
  • Loading branch information
nczirjak-acdh committed Oct 29, 2024
1 parent a89f2fd commit 0a9cf47
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 22 deletions.
58 changes: 38 additions & 20 deletions js/arche_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jQuery(function ($) {
var currentUrl = $(location).attr('href');
var apiUrl = currentUrl.replace('/browser/metadata/', '/api/');
var baseApiUrl = drupalSettings.arche_core_gui.baseApiUrl;

$(document).ready(function () {
addButtonToDescriptionText();
$('#cite-loader').removeClass('hidden');
Expand Down Expand Up @@ -50,21 +50,29 @@ jQuery(function ($) {
* @returns {undefined}
*/
function checkUserPermission() {
console.log("https://invalid:credentials@" + baseApiUrl + "/user/logout?redirect=" + apiUrl);
if ($('div').hasClass('download-login-div')) {
let resourceId = $("#resId").val();
let aclRead = $("#resource-acl-read").val();
let acdhType = $('#resource-type').val();
let resourceAccess = $('#resource-access').val();
//if the resource or collection is public then we hide the login
//and display all download possbility
if (resourceAccess === "true") {
if (resourceAccess.includes("public")) {

$('#download-resource-section').removeClass('d-none');
$('#download-not-logged').addClass('d-none');
} else {
$('#download-not-logged').removeClass('d-none');
var accessLevel = 'public';
if (resourceAccess) {
accessLevel = resourceAccess;
} else if (aclRead) {
accessLevel = aclRead;
}
//if not then we have to check the actual logged user permissions
$.ajax({
url: '/browser/api/checkUser/' + resourceId + '/' + aclRead,
url: '/browser/api/checkUser/' + resourceId + '/' + accessLevel,
method: 'GET',
success: function (data) {
if (data.length === 0 || data.access == 'login') {
Expand All @@ -73,6 +81,7 @@ jQuery(function ($) {
if (data.access == 'authorized' || (acdhType.toLowerCase() === 'collection' || acdhType.toLowerCase() === 'topcollection')) {
$('#download-resource-section').removeClass('d-none');
$('#download-logged').removeClass('d-none');
$('#download-not-logged').addClass('d-none');
$('#user-logged-text').html(data.username + ' : ' + data.roles);
$('#download-logout').removeClass('d-none');
$('#download-restricted').addClass('d-none');
Expand All @@ -83,6 +92,7 @@ jQuery(function ($) {
}
} else if (data.access == 'not authorized') {
$('#download-restricted').addClass('d-none');
$('#download-logged').removeClass('d-none');
$('#download-not-authorized').removeClass('d-none');
$('#user-logged-not-auth-text').html(data.username + ' : ' + data.roles);
$('#user-not-authorized-text').html(Drupal.t("You don't have enough rights!"));
Expand Down Expand Up @@ -383,9 +393,9 @@ jQuery(function ($) {
* @returns {undefined}
*/
function showTitleImage() {

var isPublic = $('#resource-access').val();

var imgSrc = 'https://arche-thumbnails.acdh.oeaw.ac.at?id=' + apiUrl + '&width=600';
$.ajax({
url: imgSrc,
Expand Down Expand Up @@ -463,13 +473,21 @@ jQuery(function ($) {
$(notHiddenTab + '-content').show();
}
}

//httpd logout
$(document).delegate("#httpd-logout", "click", function (e) {
window.location.href = "https://invalid:credentials@"+baseApiUrl+"/user/logout?redirect="+apiUrl;
$.ajax({
url: "/api/user/logout?redirect=" + currentUrl,
type: "GET",
headers: {
"Authorization": "Basic " + btoa("invalid:credentials")
},
error: function () {
alert("You have been logged out.");
}
});
});


/// hasDescription button ///
$(document).delegate("#descriptionTextShortBtn", "click", function (e) {
$('.descriptionTextShort').hide();
Expand Down Expand Up @@ -763,7 +781,7 @@ jQuery(function ($) {
if (!data.customCitation.startsWith('@')) {
citationText = "@dataset{" + data.id + ", " + data.customCitation + "}";
}

let citeDT = new Cite(citationText);
let templateName = 'apa-6th';
var template = "";
Expand Down Expand Up @@ -879,19 +897,19 @@ jQuery(function ($) {
function initExpertView() {
expertTable = $('#expertDT').DataTable({
"deferRender": true
//"dom": '<"top"lfp<"clear">>rt<"bottom"i<"clear">>',
//"dom": '<"top"lfp<"clear">>rt<"bottom"i<"clear">>',
});
/*
$('#expertDT').on('search.dt', function() {
var searchValue = $('#expertDT').DataTable().search(); // Get current search value
console.log("Search value: ", searchValue);
var filteredRows = $('#expertDT').DataTable().rows({ filter: 'applied' }).data();
console.log("Filtered rows after search: ", filteredRows.length);
// Optionally log all filtered rows
console.log("Filtered rows data: ", filteredRows);
});*/
$('#expertDT').on('search.dt', function() {
var searchValue = $('#expertDT').DataTable().search(); // Get current search value
console.log("Search value: ", searchValue);
var filteredRows = $('#expertDT').DataTable().rows({ filter: 'applied' }).data();
console.log("Filtered rows after search: ", filteredRows.length);
// Optionally log all filtered rows
console.log("Filtered rows data: ", filteredRows);
});*/
}

function reloadDetail(id) {
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/MetadataController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function detailView(string $identifier) {
'#theme' => 'arche-detail-empty'
];
}

$return = [
'#theme' => 'arche-detail',
'#identifier' => $identifier,
Expand Down
29 changes: 29 additions & 0 deletions src/Object/ResourceCoreObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ResourceCoreObject {
private $iiifFormats = array('image/jpeg', 'image/png', 'image/tiff');
private $publicAccessValue = 'https://vocabs.acdh.oeaw.ac.at/archeaccessrestrictions/public';
private $publicAccessTitle = ['public', 'öffentlich'];
private $accessLevels = ['public' => 'öffentlich', 'academic' => 'akademisch', 'restricted' => 'eingeschränkt'];

public function __construct(array $data, object $config, string $language = 'en') {
$this->properties = array();
Expand Down Expand Up @@ -784,6 +785,34 @@ public function isPublic(): bool {
}
return $result;
}

/**
* Get the actual resource access level for the user login check
* @return string
*/
public function getResourceAccessLevel(): string {
$access = $this->getAccessRestriction();

if(count($access) > 0) {
if($this->language == "de") {
foreach($this->accessLevels as $k => $v) {
if($v === $access['title']) {
return $k;
}
}
}
return $access['title'];
}
$aclRead = $this->getData('acdh:aclRead');
$aclReadArr = [];
if(count($aclRead) > 0) {
foreach($aclRead as $v) {
$aclReadArr[] = $v['value'];
}
return implode(',', $aclReadArr);
}
return 'public';
}

/**
* Create the VCR data json string
Expand Down
2 changes: 1 addition & 1 deletion templates/arche-detail.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<input type="hidden" value="{{ data.getTitle() }}" id="resource-main-title"/>
<input type="hidden" value="{{ data.getAcdhType()|lower|raw }}" id="resource-type"/>
<input type="hidden" value="{{ data.getDataArrayString('acdh:aclRead', 'string')|raw }}" id="resource-acl-read"/>
<input type="hidden" value="{{ data.isPublic()|json_encode }}" id="resource-access"/>
<input type="hidden" value="{{ data.getResourceAccessLevel() }}" id="resource-access"/>

{% if data.getAcdhType()|lower == 'place' %}
{{ include(arche_core_gui_path ~ '/templates/metadata/place-block.html.twig', {'data': data, 'cookie': cookie } ) }}
Expand Down

0 comments on commit 0a9cf47

Please sign in to comment.