Skip to content

Commit

Permalink
Fixes #3 (rule name was not URIEncoded).
Browse files Browse the repository at this point in the history
  • Loading branch information
Christiaan van Tienhoven committed Feb 6, 2017
1 parent cbdb8d0 commit 64f0fad
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>org.graylog.plugins.aggregates</groupId>
<artifactId>graylog-plugin-aggregates</artifactId>
<version>0.0.13</version>
<version>0.0.14</version>
<packaging>jar</packaging>

<name>${project.artifactId}</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public URI getURL() {

@Override
public Version getVersion() {
return new Version(0, 0, 13);
return new Version(0, 0, 14);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.graylog.plugins.aggregates.rule;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.graylog.plugins.aggregates.rule.rest.models.requests.AddRuleRequest;
import org.graylog.plugins.aggregates.rule.rest.models.requests.UpdateRuleRequest;

import com.mongodb.MongoException;

public interface RuleService {
long count();

Expand All @@ -14,7 +17,7 @@ public interface RuleService {

List<Rule> all();

int destroy(String ruleName);
int destroy(String ruleName) throws MongoException, UnsupportedEncodingException;

Rule fromRequest(AddRuleRequest request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.mongodb.MongoException;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
Expand Down Expand Up @@ -41,6 +43,8 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import java.io.UnsupportedEncodingException;
import java.util.List;

@Api(value = "Aggregates", description = "Management of Aggregation rules.")
Expand Down Expand Up @@ -93,10 +97,10 @@ public Response create(
public Response update(@ApiParam(name = "name", required = true)
@PathParam("name") String name,
@ApiParam(name = "JSON body", required = true) @Valid @NotNull UpdateRuleRequest request
) {
) throws UnsupportedEncodingException {
final Rule rule = ruleService.fromRequest(request);

ruleService.update(name, rule);
ruleService.update(java.net.URLDecoder.decode(name, "UTF-8"), rule);

return Response.accepted().build();
}
Expand All @@ -112,7 +116,7 @@ public Response update(@ApiParam(name = "name", required = true)
})
public void delete(@ApiParam(name = "name", required = true)
@PathParam("name") String name
) throws NotFoundException {
ruleService.destroy(name);
) throws NotFoundException, MongoException, UnsupportedEncodingException {
ruleService.destroy(java.net.URLDecoder.decode(name, "UTF-8"));
}
}
8 changes: 3 additions & 5 deletions src/web/aggregates/AggregatesStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const AggregatesStore = Reflux.createStore({
AggregatesActions.list.promise(promise);
},
create(newRule) {
console.log(JSON.stringify(newRule));
const url = URLUtils.qualifyUrl(this.sourceUrl);
const method = 'PUT';

Expand Down Expand Up @@ -61,7 +60,7 @@ const AggregatesStore = Reflux.createStore({

},
update(name, updatedRule) {
const url = URLUtils.qualifyUrl(this.sourceUrl+'/' + name);
const url = URLUtils.qualifyUrl(this.sourceUrl+'/' + encodeURIComponent(name));
const method = 'POST';

const request = {
Expand Down Expand Up @@ -92,10 +91,9 @@ const AggregatesStore = Reflux.createStore({

},
deleteByName(ruleName) {
const url = URLUtils.qualifyUrl(this.sourceUrl + '/' + ruleName);
const url = URLUtils.qualifyUrl(this.sourceUrl + '/' + encodeURIComponent(ruleName));
const method = 'DELETE';
//const request;


const promise = fetch(method, url)
.then(() => {
UserNotification.success('Rule successfully deleted');
Expand Down

0 comments on commit 64f0fad

Please sign in to comment.