diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/RestModule.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/RestModule.java index 68e8542ce6d8b2d58014bfab2f076b7b2e3ed7bc..2e3050d03bea6a29bcc165e6f6ab3c028bd705d7 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/RestModule.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/RestModule.java @@ -22,6 +22,7 @@ package org.duniter.elasticsearch.rest; * #L% */ +import org.duniter.elasticsearch.rest.attachment.RestImageAttachmentAction; import org.duniter.elasticsearch.rest.currency.RestCurrencyIndexAction; import org.duniter.elasticsearch.rest.security.RestSecurityAuthAction; import org.duniter.elasticsearch.rest.security.RestSecurityController; @@ -34,6 +35,9 @@ public class RestModule extends AbstractModule implements Module { @Override protected void configure() { + // Attachment + bind(RestImageAttachmentAction.class).asEagerSingleton(); + // Currency bind(RestCurrencyIndexAction.class).asEagerSingleton(); diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/attachment/RestImageAttachmentAction.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/attachment/RestImageAttachmentAction.java new file mode 100644 index 0000000000000000000000000000000000000000..f861333dfd6230a9538538c5b4135ebbe8273bbc --- /dev/null +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/attachment/RestImageAttachmentAction.java @@ -0,0 +1,98 @@ +package org.duniter.elasticsearch.rest.attachment; + +/* + * #%L + * duniter4j-elasticsearch-plugin + * %% + * Copyright (C) 2014 - 2016 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.duniter.core.util.StringUtils; +import org.elasticsearch.action.get.GetRequest; +import org.elasticsearch.action.get.GetResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.common.Base64; +import org.elasticsearch.common.bytes.BytesArray; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.inject.internal.Join; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.rest.*; +import org.elasticsearch.rest.action.support.RestResponseListener; +import org.elasticsearch.search.fetch.source.FetchSourceContext; + +import java.util.Arrays; +import java.util.Map; + +import static org.elasticsearch.rest.RestStatus.OK; + +public class RestImageAttachmentAction extends BaseRestHandler { + + @Inject + public RestImageAttachmentAction(Settings settings, RestController controller, Client client) { + super(settings, controller, client); + controller.registerHandler(RestRequest.Method.GET, "/{index}/{type}/{id}/_image/{field}", this); + } + + @Override + protected void handleRequest(final RestRequest request, RestChannel channel, Client client) throws Exception { + String index = request.param("index"); + String type = request.param("type"); + String id = request.param("id"); + String paramField = request.param("field"); + String[] fieldParts = paramField.split("\\."); + String extension = null; + if (fieldParts.length >= 2) { + extension = fieldParts[fieldParts.length-1]; + paramField = Join.join(".", Arrays.copyOf(fieldParts, fieldParts.length-1)); + } + + final String field = paramField; + final String expectedContentType = "image/" + extension; + + GetRequest getRequest = new GetRequest(index, type, id) + .fields(field) + .fetchSourceContext(FetchSourceContext.FETCH_SOURCE) + .realtime(true); + + client.get(getRequest, new RestResponseListener<GetResponse>(channel) { + @Override + public RestResponse buildResponse(GetResponse response) throws Exception { + if (response.getSource() == null || !response.getSource().containsKey(field)) { + return new BytesRestResponse(RestStatus.BAD_REQUEST, String.format("Field [%s] not exists.", field)); + } + Object value = response.getSource().get(field); + if (!(value instanceof Map)) { + return new BytesRestResponse(RestStatus.BAD_REQUEST, String.format("Field [%s] is not an attachment type.", field)); + } + Map<String, String> attachment = (Map<String, String>)value; + String contentType = attachment.get("_content_type"); + if (StringUtils.isBlank(contentType)) { + return new BytesRestResponse(RestStatus.BAD_REQUEST, String.format("Field [%s] not contains key [_content_type].", field)); + } + + if (!expectedContentType.equals(contentType)) { + return new BytesRestResponse(RestStatus.BAD_REQUEST, String.format("File extension not compatible with attachment content type [%s]", contentType)); + } + + return new BytesRestResponse(OK, + contentType, + new BytesArray(Base64.decode(attachment.get("_content")))); + } + }); + } +} \ No newline at end of file diff --git a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/security/RestSecurityController.java b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/security/RestSecurityController.java index 52c63a783a1fda29db8b765e488b7b23b0fed3d9..1960041034987b0ed5c5c369b083442c2399f7f5 100644 --- a/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/security/RestSecurityController.java +++ b/duniter4j-es-core/src/main/java/org/duniter/elasticsearch/rest/security/RestSecurityController.java @@ -30,7 +30,10 @@ import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.RestRequest; -import java.util.*; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; /** * Created by blavenie on 11/10/16. @@ -54,6 +57,10 @@ public class RestSecurityController extends AbstractLifecycleComponent<RestSecur return allow(method, String.format("/%s/%s(/.*)?", index, type)); } + public RestSecurityController allowImageAttachment(String index, String type, String field) { + return allow(RestRequest.Method.GET, String.format("/%s/%s/[^/]+/_image/%s.*", index, type, field)); + } + public RestSecurityController allow(RestRequest.Method method, String regexPath) { Set<String> allowRules = allowRulesByMethod.get(method); if (allowRules == null) { diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/market/MarketRecord.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/market/MarketRecord.java new file mode 100644 index 0000000000000000000000000000000000000000..499b3231956eb5deaa3076c0bc5b838a9d9bba9d --- /dev/null +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/market/MarketRecord.java @@ -0,0 +1,74 @@ +package org.duniter.elasticsearch.gchange.model.market; + +import org.duniter.core.client.model.elasticsearch.Record; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by blavenie on 01/12/16. + */ +public class MarketRecord extends Record{ + + public static final String PROPERTY_TITLE="title"; + public static final String PROPERTY_DESCRIPTION="description"; + public static final String PROPERTY_PRICE="price"; + public static final String PROPERTY_UNIT="unit"; + public static final String PROPERTY_CURRENCY="currency"; + public static final String PROPERTY_THUMBNAIL="thumbnail"; + + private String title; + private String description; + private Map<String, String> thumbnail = new HashMap<>(); + private Double price; + private String unit; + private String currency; + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } + + public String getUnit() { + return unit; + } + + public void setUnit(String unit) { + this.unit = unit; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + public Map<String, String> getThumbnail() { + return thumbnail; + } + + public void setThumbnail(Map<String, String> thumbnail) { + this.thumbnail = thumbnail; + } +} diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/MarketRecord.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/registry/RegistryRecord.java similarity index 56% rename from duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/MarketRecord.java rename to duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/registry/RegistryRecord.java index 52a48d5d01f16b8b7a65c0f8ed95cdc97a21c752..dc93447d923616168e07e4eacc99b192d6ec2263 100644 --- a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/MarketRecord.java +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/model/registry/RegistryRecord.java @@ -1,17 +1,22 @@ -package org.duniter.elasticsearch.gchange.model; +package org.duniter.elasticsearch.gchange.model.registry; import org.duniter.core.client.model.elasticsearch.Record; +import java.util.HashMap; +import java.util.Map; + /** * Created by blavenie on 01/12/16. */ -public class MarketRecord extends Record{ +public class RegistryRecord extends Record{ public static final String PROPERTY_TITLE="title"; public static final String PROPERTY_DESCRIPTION="description"; + public static final String PROPERTY_THUMBNAIL="thumbnail"; private String title; private String description; + private Map<String, String> thumbnail = new HashMap<>(); public String getTitle() { return title; @@ -28,4 +33,13 @@ public class MarketRecord extends Record{ public void setDescription(String description) { this.description = description; } + + public Map<String, String> getThumbnail() { + return thumbnail; + } + + public void setThumbnail(Map<String, String> thumbnail) { + this.thumbnail = thumbnail; + } + } diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/RestModule.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/RestModule.java index 4f45cec511d95315fb6fb73a46d6c38e8679418f..d7ee15f72cfa2fa87b0bb298a7d2e6980d3f5aa6 100644 --- a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/RestModule.java +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/RestModule.java @@ -37,12 +37,14 @@ public class RestModule extends AbstractModule implements Module { bind(RestMarketCommentIndexAction.class).asEagerSingleton(); bind(RestMarketCommentUpdateAction.class).asEagerSingleton(); bind(RestMarketCategoryAction.class).asEagerSingleton(); + bind(RestMarketImageAction.class).asEagerSingleton(); // Registry bind(RestRegistryRecordIndexAction.class).asEagerSingleton(); bind(RestRegistryRecordUpdateAction.class).asEagerSingleton(); bind(RestRegistryCommentIndexAction.class).asEagerSingleton(); - bind(RestregistryCommentUpdateAction.class).asEagerSingleton(); + bind(RestRegistryCommentUpdateAction.class).asEagerSingleton(); bind(RestRegistryCategoryAction.class).asEagerSingleton(); + bind(RestRegistryImageAction.class).asEagerSingleton(); } } \ No newline at end of file diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/market/RestMarketImageAction.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/market/RestMarketImageAction.java new file mode 100644 index 0000000000000000000000000000000000000000..20a075618736885d36bc21f3d679a283314d46f2 --- /dev/null +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/market/RestMarketImageAction.java @@ -0,0 +1,43 @@ +package org.duniter.elasticsearch.gchange.rest.market; + +/* + * #%L + * duniter4j-elasticsearch-plugin + * %% + * Copyright (C) 2014 - 2016 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.duniter.elasticsearch.gchange.model.market.MarketRecord; +import org.duniter.elasticsearch.gchange.model.registry.RegistryRecord; +import org.duniter.elasticsearch.gchange.service.MarketService; +import org.duniter.elasticsearch.gchange.service.RegistryService; +import org.duniter.elasticsearch.rest.security.RestSecurityController; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.rest.RestRequest; + +public class RestMarketImageAction { + + @Inject + public RestMarketImageAction(RestSecurityController securityController) { + + // Allow to get thumbnail + securityController.allowImageAttachment(MarketService.INDEX, MarketService.RECORD_TYPE, MarketRecord.PROPERTY_THUMBNAIL); + + // TODO : allow to get pictures + } +} \ No newline at end of file diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/registry/RestregistryCommentUpdateAction.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/registry/RestRegistryCommentUpdateAction.java similarity index 92% rename from duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/registry/RestregistryCommentUpdateAction.java rename to duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/registry/RestRegistryCommentUpdateAction.java index 464b0f763ec65f6650d5a54521cca06acb59a165..5b4433b4894635212b78f2d71164abb4b706fe43 100644 --- a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/registry/RestregistryCommentUpdateAction.java +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/registry/RestRegistryCommentUpdateAction.java @@ -30,10 +30,10 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.RestController; -public class RestregistryCommentUpdateAction extends AbstractRestPostUpdateAction { +public class RestRegistryCommentUpdateAction extends AbstractRestPostUpdateAction { @Inject - public RestregistryCommentUpdateAction(Settings settings, RestController controller, Client client, RestSecurityController securityController, + public RestRegistryCommentUpdateAction(Settings settings, RestController controller, Client client, RestSecurityController securityController, RegistryService service) { super(settings, controller, client, securityController, RegistryService.INDEX, RegistryService.RECORD_COMMENT_TYPE, diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/registry/RestRegistryImageAction.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/registry/RestRegistryImageAction.java new file mode 100644 index 0000000000000000000000000000000000000000..7a2293955671bc79c62c2441fed93c3cf71bbba5 --- /dev/null +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/rest/registry/RestRegistryImageAction.java @@ -0,0 +1,42 @@ +package org.duniter.elasticsearch.gchange.rest.registry; + +/* + * #%L + * duniter4j-elasticsearch-plugin + * %% + * Copyright (C) 2014 - 2016 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.duniter.elasticsearch.gchange.model.registry.RegistryRecord; +import org.duniter.elasticsearch.gchange.service.RegistryService; +import org.duniter.elasticsearch.rest.security.RestSecurityController; +import org.duniter.elasticsearch.user.service.UserService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.rest.RestRequest; + +public class RestRegistryImageAction { + + @Inject + public RestRegistryImageAction(RestSecurityController securityController) { + + // Allow to get thumbnail + securityController.allowImageAttachment(RegistryService.INDEX, RegistryService.RECORD_TYPE, RegistryRecord.PROPERTY_THUMBNAIL); + + // TODO : allow to get pictures + } +} \ No newline at end of file diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/CommentService.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/CommentService.java index 143fb0743fcd17b721d19fc0d63a1cb2c535c1c8..82da51d748c0e3cbe978d01bb51ace4471756953 100644 --- a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/CommentService.java +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/CommentService.java @@ -32,7 +32,7 @@ import org.duniter.core.service.CryptoService; import org.duniter.elasticsearch.exception.DocumentNotFoundException; import org.duniter.elasticsearch.exception.NotFoundException; import org.duniter.elasticsearch.gchange.PluginSettings; -import org.duniter.elasticsearch.gchange.model.MarketRecord; +import org.duniter.elasticsearch.gchange.model.market.MarketRecord; import org.duniter.elasticsearch.gchange.model.event.GchangeEventCodes; import org.duniter.elasticsearch.service.AbstractService; import org.duniter.elasticsearch.threadpool.ThreadPool; diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/CommentUserEventService.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/CommentUserEventService.java index 2605a9a74aaf6774ff2f58c520225ebf66c10913..3798b991f18b8ac3e172e366d33dab1ac602c9f4 100644 --- a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/CommentUserEventService.java +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/CommentUserEventService.java @@ -33,7 +33,7 @@ import org.duniter.core.exception.TechnicalException; import org.duniter.core.service.CryptoService; import org.duniter.core.util.websocket.WebsocketClientEndpoint; import org.duniter.elasticsearch.PluginSettings; -import org.duniter.elasticsearch.gchange.model.MarketRecord; +import org.duniter.elasticsearch.gchange.model.market.MarketRecord; import org.duniter.elasticsearch.gchange.model.event.GchangeEventCodes; import org.duniter.elasticsearch.service.AbstractService; import org.duniter.elasticsearch.service.BlockchainService; diff --git a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/MarketService.java b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/MarketService.java index ad85e7dfca1855e176f4c992a05bab4194de4878..898699303684126fe9b3eb907017f57504e36f6c 100644 --- a/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/MarketService.java +++ b/duniter4j-es-gchange/src/main/java/org/duniter/elasticsearch/gchange/service/MarketService.java @@ -24,21 +24,13 @@ package org.duniter.elasticsearch.gchange.service; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import org.apache.commons.collections4.MapUtils; -import org.duniter.core.client.model.elasticsearch.RecordComment; import org.duniter.core.client.service.bma.WotRemoteService; import org.duniter.core.exception.TechnicalException; import org.duniter.core.service.CryptoService; -import org.duniter.elasticsearch.exception.DocumentNotFoundException; import org.duniter.elasticsearch.gchange.PluginSettings; -import org.duniter.elasticsearch.gchange.model.MarketRecord; -import org.duniter.elasticsearch.gchange.model.event.GchangeEventCodes; import org.duniter.elasticsearch.service.AbstractService; import org.duniter.elasticsearch.service.ServiceLocator; import org.duniter.elasticsearch.threadpool.ThreadPool; -import org.duniter.elasticsearch.user.model.UserEvent; -import org.duniter.elasticsearch.user.service.UserService; import org.duniter.elasticsearch.user.service.UserEventService; import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.index.IndexRequestBuilder; @@ -48,10 +40,8 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; -import org.nuiton.i18n.I18n; import java.io.IOException; -import java.util.Map; /** * Created by Benoit on 30/03/2015. diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/model/UserProfile.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/model/UserProfile.java index 54608f008094406c3d2e74ef7e7506fc56cfcb3a..73ad472a7312f6173c6a1db8f3ce86bccfa4d266 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/model/UserProfile.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/model/UserProfile.java @@ -34,6 +34,7 @@ public class UserProfile extends Record { public static final String PROPERTY_CITY="city"; public static final String PROPERTY_EMAIL="email"; public static final String PROPERTY_LOCALE="locale"; + public static final String PROPERTY_AVATAR="avatar"; private String title; private String description; diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/RestModule.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/RestModule.java index 7c4275aef625502e97263e6b08975bab94d72203..fc6d2dede07a396bc56a7cc4d093d7f25f8fddb0 100644 --- a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/RestModule.java +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/RestModule.java @@ -47,6 +47,7 @@ public class RestModule extends AbstractModule implements Module { bind(RestUserSettingsUpdateAction.class).asEagerSingleton(); bind(RestUserEventMarkAsReadAction.class).asEagerSingleton(); bind(RestUserEventSearchAction.class).asEagerSingleton(); + bind(RestUserAvatarAction.class).asEagerSingleton(); // Group bind(RestGroupIndexAction.class).asEagerSingleton(); diff --git a/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserAvatarAction.java b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserAvatarAction.java new file mode 100644 index 0000000000000000000000000000000000000000..11a606a7bf9a54081d8a47e85a8a4b00eeb09476 --- /dev/null +++ b/duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/rest/user/RestUserAvatarAction.java @@ -0,0 +1,40 @@ +package org.duniter.elasticsearch.user.rest.user; + +/* + * #%L + * duniter4j-elasticsearch-plugin + * %% + * Copyright (C) 2014 - 2016 EIS + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/gpl-3.0.html>. + * #L% + */ + +import org.duniter.elasticsearch.rest.security.RestSecurityController; +import org.duniter.elasticsearch.user.model.UserProfile; +import org.duniter.elasticsearch.user.service.UserService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.rest.RestRequest; + +public class RestUserAvatarAction { + + @Inject + public RestUserAvatarAction(RestSecurityController securityController) { + + // Allow to get avatar as image + securityController.allowImageAttachment(UserService.INDEX, UserService.PROFILE_TYPE, UserProfile.PROPERTY_AVATAR); + + } +} \ No newline at end of file