diff options
| author | reger24 <11603289+reger24@users.noreply.github.com> | 2022-02-11 04:25:26 +0100 |
|---|---|---|
| committer | reger24 <11603289+reger24@users.noreply.github.com> | 2022-02-11 04:25:26 +0100 |
| commit | 84651f2925270b6885887b1514094122b048bf21 (patch) | |
| tree | ecc23a7e651ede61a410bac719bc9e545b4df4b9 /htroot | |
| parent | 2d53147d7f9eba46766ddd3fc83a640727912982 (diff) | |
Make bookmarks.html accessible
for the time beeing (as possibliy other decision has been made)
make the bookmarks feature accessible, as it is available but w/o link in UI
relates to https://github.com/yacy/yacy_search_server/issues/452#issuecomment-1033054368
Diffstat (limited to 'htroot')
| -rw-r--r-- | htroot/env/templates/submenuComputation.template | 1 | ||||
| -rw-r--r-- | htroot/yacysearch.java | 34 | ||||
| -rw-r--r-- | htroot/yacysearchitem.java | 46 |
3 files changed, 69 insertions, 12 deletions
diff --git a/htroot/env/templates/submenuComputation.template b/htroot/env/templates/submenuComputation.template index b6062bcf8..9b24c0226 100644 --- a/htroot/env/templates/submenuComputation.template +++ b/htroot/env/templates/submenuComputation.template @@ -33,6 +33,7 @@ <ul class="SubMenu"> <li><a href="Surftips.html" class="MenuItemLink">Surftips</a></li> <li><a href="Wiki.html?display=1" class="MenuItemLink">Local Peer Wiki</a></li> + <li><a href="Bookmarks.html" class="MenuItemLink #(authorized)#lock::unlock#(/authorized)#">Bookmarks</a></li> </ul> </div> </div> diff --git a/htroot/yacysearch.java b/htroot/yacysearch.java index a5a6df4ea..c318f7baf 100644 --- a/htroot/yacysearch.java +++ b/htroot/yacysearch.java @@ -63,6 +63,7 @@ import net.yacy.cora.protocol.HeaderFramework; import net.yacy.cora.protocol.RequestHeader; import net.yacy.cora.protocol.ResponseHeader; import net.yacy.cora.util.ConcurrentLog; +import net.yacy.data.BookmarksDB.Bookmark; import net.yacy.data.DidYouMean; import net.yacy.data.UserDB; import net.yacy.document.LibraryProvider; @@ -112,14 +113,15 @@ public class yacysearch { final boolean searchAllowed = sb.getConfigBool(SwitchboardConstants.PUBLIC_SEARCHPAGE, true) || adminAuthenticated; boolean extendedSearchRights = adminAuthenticated; - - if(adminAuthenticated) { + boolean bookmarkRights = false; + if (adminAuthenticated) { authenticatedUserName = sb.getConfig(SwitchboardConstants.ADMIN_ACCOUNT_USER_NAME, "admin"); } else { final UserDB.Entry user = sb.userDB != null ? sb.userDB.getUser(header) : null; - if(user != null) { + if (user != null) { extendedSearchRights = user.hasRight(UserDB.AccessRight.EXTENDED_SEARCH_RIGHT); authenticatedUserName = user.getUserName(); + bookmarkRights = user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT); } } @@ -701,7 +703,31 @@ public class yacysearch { } } - // if a blacklist-button was hit, add host to default blacklist + // if a bookmarks-button was hit, create new bookmark entry + if (post != null && post.containsKey("bookmarkref")) { + if (!sb.verifyAuthentication(header) && !bookmarkRights) { + prop.authenticationRequired(); + return prop; + } + //final String bookmarkHash = post.get("bookmarkref", ""); // urlhash + final String urlstr = crypt.simpleDecode(post.get("bookmarkurl")); + if (urlstr != null) { + final Bookmark bmk = sb.bookmarksDB.createorgetBookmark(urlstr, "admin"); + if (bmk != null) { + bmk.setProperty(Bookmark.BOOKMARK_QUERY, querystring); + bmk.addTag("/search"); // add to bookmark folder + bmk.addTag("searchresult"); // add tag + String urlhash = post.get("bookmarkref"); + final URIMetadataNode urlentry = indexSegment.fulltext().getMetadata(UTF8.getBytes(urlhash)); + if (urlentry != null && !urlentry.dc_title().isEmpty()) { + bmk.setProperty(Bookmark.BOOKMARK_TITLE, urlentry.dc_title()); + } + sb.bookmarksDB.saveBookmark(bmk); + } + } + } + + // if a blacklist-button was hit, add host to default blacklist if (post != null && post.containsKey("blacklisturl")) { if (!sb.verifyAuthentication(header)) { diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.java index 812104d46..a83d478f9 100644 --- a/htroot/yacysearchitem.java +++ b/htroot/yacysearchitem.java @@ -65,6 +65,7 @@ import net.yacy.kelondro.util.Formatter; import net.yacy.peers.NewsPool; import net.yacy.peers.Seed; import net.yacy.peers.graphics.ProfilingGraph; +import net.yacy.repository.Blacklist; import net.yacy.search.EventTracker; import net.yacy.search.Switchboard; import net.yacy.search.SwitchboardConstants; @@ -109,6 +110,7 @@ public class yacysearchitem { final boolean authenticated = adminAuthenticated || user != null; final boolean extendedSearchRights = adminAuthenticated || (user != null && user.hasRight(UserDB.AccessRight.EXTENDED_SEARCH_RIGHT)); + final boolean bookmarkRights = adminAuthenticated || (user != null && user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT)); final int item = post.getInt("item", -1); final RequestHeader.FileType fileType = header.fileType(); @@ -173,10 +175,21 @@ public class yacysearchitem { final String resource = theSearch.query.domType.toString(); final String origQ = theSearch.query.getQueryGoal().getQueryString(true); prop.put("content", 1); // switch on specific content - prop.put("content_authorized", adminAuthenticated ? "1" : "0"); final String urlhash = ASCII.String(result.hash()); if (adminAuthenticated) { // only needed if authorized - addAuthorizedActions(sb, prop, theSearch, resultUrlstring, resource, origQ, urlhash); + addAuthorizedActions(sb, prop, theSearch, resultUrlstring, resource, origQ, urlhash, null); + } else if (authenticated && user != null) { + addAuthorizedActions(sb, prop, theSearch, resultUrlstring, resource, origQ, urlhash, user); + } else + prop.put("content_authorized", "0"); // disable for not authorized user +// for testing only +// result +// if local Admin - no admin_right +// if admin authent -> admin_right = true, bookmark_right = false + if (header.isUserInRole(UserDB.AccessRight.ADMIN_RIGHT.toString())) { + if (header.isUserInRole(UserDB.AccessRight.BOOKMARK_RIGHT.toString())) { + System.out.println("booki"); + } } prop.putHTML("content_title", result.title()); prop.putXML("content_title-xml", result.title()); @@ -678,14 +691,23 @@ public class yacysearchitem { * @param resource resource scope ("local" or "global") * @param origQ origin query terms * @param urlhash URL hash of the result item + * @param user current user or null if current user is admin */ private static void addAuthorizedActions(final Switchboard sb, final serverObjects prop, final SearchEvent theSearch, final String resultUrlstring, final String resource, final String origQ, - final String urlhash) { + final String urlhash, UserDB.Entry user) { // check if url exists in bookmarks boolean bookmarkexists = sb.bookmarksDB.getBookmark(urlhash) != null; - prop.put("content_authorized_bookmark", !bookmarkexists); - + if (user == null || user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT)) { + prop.put("content_authorized_bookmark", !bookmarkexists); + } else + prop.put("content_authorized_bookmark", "0"); +/* boolean blacklistislisted = false; + try { + DigestURL durl = new DigestURL(resultUrlstring); + blacklistislisted = sb.urlBlacklist.isListed(Blacklist.BlacklistType.SEARCH, durl); + } catch (Exception e) {} +*/ final StringBuilder linkBuilder = QueryParams.navurl(RequestHeader.FileType.HTML, theSearch.query.offset / theSearch.query.itemsPerPage(), theSearch.query, null, false, true); final int baseUrlLength = linkBuilder.length(); @@ -697,7 +719,7 @@ public class yacysearchitem { ConcurrentLog.warn("YACY_SEARCH_ITEM", "UTF-8 encoding is not supported!"); encodedURLString = crypt.simpleEncode(resultUrlstring); } - final String bookmarkLink = linkBuilder.append("&bookmarkurl=").append(encodedURLString).toString(); + final String bookmarkLink = linkBuilder.append("&bookmarkurl=").append(encodedURLString).append("&bookmarkref=" + urlhash).toString(); linkBuilder.setLength(baseUrlLength); String deleteLink = linkBuilder.append("&deleteref=").append(urlhash).toString(); @@ -714,10 +736,18 @@ public class yacysearchitem { prop.put("content_authorized_recommend_deletelink", deleteLink); prop.put("content_authorized_recommend_recommendlink", recommendLink); - prop.put("content_authorized_recommend", (sb.peers.newsPool.getSpecific(NewsPool.OUTGOING_DB, NewsPool.CATEGORY_SURFTIPP_ADD, "url", resultUrlstring) == null) ? "1" : "0"); - prop.put("content_authorized_blacklist", "1"); + if (user == null || user.hasRight(UserDB.AccessRight.ADMIN_RIGHT)) { + prop.put("content_authorized_recommend", (sb.peers.newsPool.getSpecific(NewsPool.OUTGOING_DB, NewsPool.CATEGORY_SURFTIPP_ADD, "url", resultUrlstring) == null) ? "1" : "0"); + prop.put("content_authorized_blacklist", "1"); + } else { + prop.put("content_authorized_recommend", "0"); + prop.put("content_authorized_blacklist", "0"); + } + // prop.put("content_authorized_urlhash", urlhash); // not used 2022-02-09 + prop.put("content_authorized", "1"); // enable authorized icons/content } + /** * Process search of image type and feed prop object. All parameters must not be null. * @param sb Switchboard instance |
