Selaa lähdekoodia

expose account locale and lang to js context, sort blocked users case-insensitively by locale

tags/v1.0.0
Jonathan Cobb 4 vuotta sitten
vanhempi
commit
6b14af1e0a
4 muutettua tiedostoa jossa 22 lisäystä ja 10 poistoa
  1. +15
    -5
      bubble-server/src/main/java/bubble/rule/AbstractAppRuleDriver.java
  2. +2
    -2
      bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockRuleDriver.java
  3. +4
    -2
      bubble-server/src/main/resources/bubble/rule/social/block/JsUserBlockerRuleDriver.js.hbs
  4. +1
    -1
      utils/cobbzilla-utils

+ 15
- 5
bubble-server/src/main/java/bubble/rule/AbstractAppRuleDriver.java Näytä tiedosto

@@ -27,6 +27,7 @@ import org.cobbzilla.util.handlebars.HandlebarsUtil;
import org.cobbzilla.util.io.FileUtil;
import org.cobbzilla.util.io.regex.RegexFilterReader;
import org.cobbzilla.util.io.regex.RegexReplacementFilter;
import org.cobbzilla.util.string.LocaleUtil;
import org.cobbzilla.util.system.Bytes;
import org.cobbzilla.wizard.cache.redis.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -40,7 +41,8 @@ import java.util.Map;
import static bubble.ApiConstants.HOME_DIR;
import static bubble.rule.RequestModifierRule.ICON_JS_TEMPLATE;
import static bubble.rule.RequestModifierRule.ICON_JS_TEMPLATE_NAME;
import static org.cobbzilla.util.daemon.ZillaRuntime.*;
import static org.cobbzilla.util.daemon.ZillaRuntime.die;
import static org.cobbzilla.util.daemon.ZillaRuntime.empty;
import static org.cobbzilla.util.io.FileUtil.abs;
import static org.cobbzilla.util.io.FileUtil.basename;
import static org.cobbzilla.util.io.regex.RegexReplacementFilter.DEFAULT_PREFIX_REPLACEMENT_WITH_MATCH;
@@ -157,7 +159,7 @@ public abstract class AbstractAppRuleDriver implements AppRuleDriver {
final RequestModifierConfig modConfig = requestModConfig();
final String replacement = DEFAULT_PREFIX_REPLACEMENT_WITH_MATCH
+ scriptOpen(filterRequest, modConfig.getScriptOpenNonce(), modConfig.getScriptOpenNoNonce())
+ getBubbleJs(filterRequest.getId(), filterCtx, bubbleJsTemplate, defaultSiteTemplate, siteJsInsertionVar, showIcon)
+ getBubbleJs(filterRequest, filterCtx, bubbleJsTemplate, defaultSiteTemplate, siteJsInsertionVar, showIcon)
+ getScriptClose();

final RegexReplacementFilter filter = new RegexReplacementFilter(getInsertionRegex(), replacement);
@@ -179,13 +181,13 @@ public abstract class AbstractAppRuleDriver implements AppRuleDriver {
return new ReaderInputStream(reader, UTF8cs);
}

protected String getBubbleJs(String requestId,
protected String getBubbleJs(FilterHttpRequest filterRequest,
Map<String, Object> filterCtx,
String bubbleJsTemplate,
String defaultSiteTemplate,
String siteJsInsertionVar,
boolean showIcon) {
final Map<String, Object> ctx = getBubbleJsContext(requestId, filterCtx);
final Map<String, Object> ctx = getBubbleJsContext(filterRequest, filterCtx);

if (!empty(siteJsInsertionVar) && !empty(defaultSiteTemplate)) {
final String siteJs = HandlebarsUtil.apply(getHandlebars(), getSiteJsTemplate(defaultSiteTemplate), ctx);
@@ -208,6 +210,8 @@ public abstract class AbstractAppRuleDriver implements AppRuleDriver {
public static final String CTX_BUBBLE_APP_NAME = "BUBBLE_APP_NAME";
public static final String CTX_ICON_JS = "ICON_JS";
public static final String CTX_APP_CONTROLS_Z_INDEX = "APP_CONTROLS_Z_INDEX";
public static final String CTX_ACCOUNT_LOCALE = "ACCOUNT_LOCALE";
public static final String CTX_ACCOUNT_LANG = "ACCOUNT_LANG";

public static final int PAGE_ONREADY_INTERVAL = 50;
public static final int APP_CONTROLS_Z_INDEX = 2147483640;
@@ -215,7 +219,8 @@ public abstract class AbstractAppRuleDriver implements AppRuleDriver {
private String getPagePrefix(String requestId) { return "__bubble_page_"+sha256_hex(requestId); }
private String getJsPrefix(String requestId) { return "__bubble_js_"+sha256_hex(requestId+"_"+getClass().getName()); }

protected Map<String, Object> getBubbleJsContext(String requestId, Map<String, Object> filterCtx) {
protected Map<String, Object> getBubbleJsContext(FilterHttpRequest filterRequest, Map<String, Object> filterCtx) {
final String requestId = filterRequest.getId();
final Map<String, Object> ctx = new HashMap<>();
ctx.put(CTX_PAGE_PREFIX, getPagePrefix(requestId));
ctx.put(CTX_JS_PREFIX, getJsPrefix(requestId));
@@ -226,6 +231,11 @@ public abstract class AbstractAppRuleDriver implements AppRuleDriver {
ctx.put(CTX_BUBBLE_SITE_NAME, getSiteName(matcher));
ctx.put(CTX_BUBBLE_APP_NAME, app.getName());
ctx.put(CTX_BUBBLE_DATA_ID, getDataId(requestId));

String locale = filterRequest.getAccount().getLocale();
if (empty(locale)) locale = configuration.getDefaultLocale();
ctx.put(CTX_ACCOUNT_LOCALE, locale);
ctx.put(CTX_ACCOUNT_LANG, LocaleUtil.getLang(locale));
return ctx;
}



+ 2
- 2
bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockRuleDriver.java Näytä tiedosto

@@ -384,8 +384,8 @@ public class BubbleBlockRuleDriver extends TrafficAnalyticsRuleDriver implements
private static final String CTX_BUBBLE_BLACKLIST = "BUBBLE_BLACKLIST_JSON";
private static final String CTX_BUBBLE_WHITELIST = "BUBBLE_WHITELIST_JSON";

@Override protected Map<String, Object> getBubbleJsContext(String requestId, Map<String, Object> filterCtx) {
final Map<String, Object> ctx = super.getBubbleJsContext(requestId, filterCtx);
@Override protected Map<String, Object> getBubbleJsContext(FilterHttpRequest filterRequest, Map<String, Object> filterCtx) {
final Map<String, Object> ctx = super.getBubbleJsContext(filterRequest, filterCtx);
final BubbleBlockConfig bubbleBlockConfig = getRuleConfig();
if (bubbleBlockConfig.inPageBlocks()) {
final BlockDecision decision = (BlockDecision) filterCtx.get(FILTER_CTX_DECISION);


+ 4
- 2
bubble-server/src/main/resources/bubble/rule/social/block/JsUserBlockerRuleDriver.js.hbs Näytä tiedosto

@@ -153,8 +153,10 @@ function {{JS_PREFIX}}_show_app_details() {
}
detailsDiv.style.display = 'block';
// add rows for blocked users...
blocks = blocks.slice(); // copy first, then sort
blocks.sort();
blocks = blocks.slice(); // copy first, then sort case insensitive using user's locale
blocks.sort(function (a, b) {
return a.localeCompare(b, '{{ACCOUNT_LANG}}', {'sensitivity': 'base'});
});
if ({{JS_PREFIX}}_unblocked_users_needs_refresh) {
const refreshControl = document.createElement('a');
refreshControl.addEventListener("click", function (e) {


+ 1
- 1
utils/cobbzilla-utils

@@ -1 +1 @@
Subproject commit 3de70e3b1e5109a0d1bf41e8d6e73358236d5e8f
Subproject commit f4e97cba4c2a47622ef648b4c94dee04e4ba4805

Ladataan…
Peruuta
Tallenna