Преглед на файлове

enable/disable blocklists working

tags/v0.5.0
Jonathan Cobb преди 4 години
родител
ревизия
8c13a90d44
променени са 7 файла, в които са добавени 108 реда и са изтрити 5 реда
  1. +48
    -3
      bubble-server/src/main/java/bubble/app/bblock/BubbleBlockAppConfigDriver.java
  2. +9
    -0
      bubble-server/src/main/java/bubble/model/app/config/AppConfigDriver.java
  3. +26
    -0
      bubble-server/src/main/java/bubble/resources/app/AppConfigResource.java
  4. +16
    -0
      bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockConfig.java
  5. +4
    -0
      bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockList.java
  6. +4
    -1
      bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties
  7. +1
    -1
      bubble-web

+ 48
- 3
bubble-server/src/main/java/bubble/app/bblock/BubbleBlockAppConfigDriver.java Целия файл

@@ -10,12 +10,15 @@ import bubble.model.app.config.AppConfigDriver;
import bubble.rule.bblock.BubbleBlockConfig;
import bubble.rule.bblock.BubbleBlockList;
import bubble.rule.bblock.BubbleBlockRuleDriver;
import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static org.cobbzilla.util.daemon.ZillaRuntime.empty;
import static org.cobbzilla.util.json.JsonUtil.json;
@@ -63,10 +66,52 @@ public class BubbleBlockAppConfigDriver implements AppConfigDriver {
final RuleDriver driver = driverDAO.findByAccountAndId(account.getUuid(), rule.getDriver());
if (driver != null && driver.getDriverClass().equals(BubbleBlockRuleDriver.class.getName())) {
final BubbleBlockConfig blockConfig = json(rule.getConfigJson(), BubbleBlockConfig.class);
blockLists.addAll(asList(blockConfig.getBlockLists()));
blockLists.addAll( Arrays.stream(blockConfig.getBlockLists())
.map(list -> list.setRule(rule))
.collect(Collectors.toList()) );
}
}
return blockLists;
}

public static final String ACTION_enable_list = "enable_list";
public static final String ACTION_disable_list = "disable_list";
public static final String ACTION_manage_list = "manage_list";
public static final String ACTION_remove_list = "remove_list";
public static final String ACTION_add_list = "add_list";
public static final String ACTION_manage_list_entries = "manage_list_entries";
public static final String ACTION_remove_rule = "remove_rule";
public static final String ACTION_create_rule = "create_rule";
public static final String ACTION_test_url = "test_url";

@Override public Object takeItemAction(Account account,
BubbleApp app,
String view,
String action,
String id,
Map<String, String> queryParams,
JsonNode data) {
BubbleBlockList list;

switch (action) {
case ACTION_enable_list:
list = loadList(account, app, id);
if (list == null) throw notFoundEx(id);
return updateList(list.setEnabled(true));

case ACTION_disable_list:
list = loadList(account, app, id);
if (list == null) throw notFoundEx(id);
return updateList(list.setEnabled(false));
}

throw notFoundEx(action);
}

private BubbleBlockList updateList(BubbleBlockList list) {
final AppRule rule = list.getRule();
final BubbleBlockConfig blockConfig = json(rule.getConfigJson(), BubbleBlockConfig.class);
ruleDAO.update(rule.setConfigJson(json(blockConfig.updateList(list))));
return list;
}
}

+ 9
- 0
bubble-server/src/main/java/bubble/model/app/config/AppConfigDriver.java Целия файл

@@ -2,6 +2,7 @@ package bubble.model.app.config;

import bubble.model.account.Account;
import bubble.model.app.BubbleApp;
import com.fasterxml.jackson.databind.JsonNode;

import java.util.Map;

@@ -11,4 +12,12 @@ public interface AppConfigDriver {

Object getView(Account account, BubbleApp app, String view, Map<String, String> params);

Object takeItemAction(Account account,
BubbleApp app,
String view,
String action,
String id,
Map<String, String> params,
JsonNode data);

}

+ 26
- 0
bubble-server/src/main/java/bubble/resources/app/AppConfigResource.java Целия файл

@@ -5,6 +5,7 @@ import bubble.model.app.BubbleApp;
import bubble.model.app.config.AppConfigDriver;
import bubble.model.app.config.AppConfigView;
import bubble.server.BubbleConfiguration;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.slf4j.Slf4j;
import org.glassfish.grizzly.http.server.Request;
import org.glassfish.jersey.server.ContainerRequest;
@@ -16,6 +17,8 @@ import javax.ws.rs.core.Response;

import java.util.Map;

import static bubble.ApiConstants.EP_ACTIONS;
import static org.cobbzilla.util.daemon.ZillaRuntime.empty;
import static org.cobbzilla.util.http.HttpContentTypes.APPLICATION_JSON;
import static org.cobbzilla.util.http.URIUtil.queryParams;
import static org.cobbzilla.wizard.resources.ResourceUtil.*;
@@ -61,4 +64,27 @@ public class AppConfigResource {
return ok(configDriver.getView(account, app, view, queryParams));
}

@POST @Path("/{view}"+EP_ACTIONS+"/{action}")
public Response takeConfigItemAction(@Context Request req,
@Context ContainerRequest ctx,
@PathParam("view") String view,
@PathParam("action") String action,
@QueryParam("id") String id,
JsonNode data) {

final Account caller = userPrincipal(ctx);
if (!caller.admin() && !caller.getUuid().equals(account.getUuid())) return forbidden();

final AppConfigView configView = app.getDataConfig().getConfigView(view);
if (configView == null) return notFound(view);

if (empty(id)) return invalid("err.id.required");
if (empty(action)) return invalid("err.action.required");

final Map<String, String> queryParams = queryParams(req.getQueryString());

final AppConfigDriver configDriver = getConfigDriver();
return ok(configDriver.takeItemAction(account, app, view, action, id, queryParams, data));
}

}

+ 16
- 0
bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockConfig.java Целия файл

@@ -3,10 +3,26 @@ package bubble.rule.bblock;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.cobbzilla.util.collection.ArrayUtil;

@NoArgsConstructor
public class BubbleBlockConfig {

@Getter @Setter private BubbleBlockList[] blockLists;

public BubbleBlockConfig updateList(BubbleBlockList list) {
if (blockLists == null) {
blockLists = new BubbleBlockList[] {list};
return this;
}
for (int i=0; i<blockLists.length; i++) {
if (blockLists[i].getId().equals(list.getId())) {
blockLists[i] = list;
return this;
}
}
blockLists = ArrayUtil.append(blockLists, list);
return this;
}

}

+ 4
- 0
bubble-server/src/main/java/bubble/rule/bblock/BubbleBlockList.java Целия файл

@@ -1,5 +1,7 @@
package bubble.rule.bblock;

import bubble.model.app.AppRule;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@@ -33,4 +35,6 @@ public class BubbleBlockList {
@Getter @Setter private Boolean enabled = true;
public boolean enabled() { return enabled != null && enabled; }

@JsonIgnore @Getter @Setter private AppRule rule;

}

+ 4
- 1
bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties Целия файл

@@ -385,13 +385,15 @@ button_label_app_data_refresh=Search
# App Config
loading_app_config_data=Loading app configuration...
table_title_app_config_views=App Configuration
message_no_config_data=No Configuration InformationFound
message_config_data_actions=Actions
message_no_config_data=No Configuration Information Found

# AppSite
loading_app_site=Loading site...
table_title_app_site_view=App Site Views

# Error messages from API server
err.action.required=No action provided
err.accountContactsJson.length=Account contacts length violation
err.accountOperationTimeout.required=Account operation timeout is required
err.accountOperationTimeout.tooLong=Account operation timeout cannot be longer than 3 days
@@ -482,6 +484,7 @@ err.fqdn.plan.invalid=No plan found for network
err.fqdn.required=FQDN is required
err.geoService.unresolvable=Error resolving geo service
err.geoTimeService.notFound=GeoTime service not found
err.id.required=Parameter 'id' is required
err.info.invalid=Contact info is invalid (must be empty for authenticator)
err.info.required=Contact info is required
err.installSshKey.cannotInstallAsNonAdmin=Must be admin to install an SSH key


+ 1
- 1
bubble-web

@@ -1 +1 @@
Subproject commit 803f4769f90ebfb5815ec35fff62b020fbae2f66
Subproject commit 1f322d388b0751bd2df8fcdcd5a2b43f7d1068a6

Зареждане…
Отказ
Запис