Skip to content

Commit

Permalink
feat: Implement simple storage attachments upload - MEED-8222,MEED-8238,
Browse files Browse the repository at this point in the history
MEED-8224,MEED-8223 - Meeds-io/MIPs#176

Implement simple storage attachments upload
  • Loading branch information
hakermi committed Feb 3, 2025
1 parent 3a685db commit f2f71c6
Show file tree
Hide file tree
Showing 25 changed files with 888 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,13 @@ public abstract class AttachmentPlugin extends BaseComponentPlugin {
*/
public abstract long getSpaceId(String objectId) throws ObjectNotFoundException;

/**
* Determines whether the attachment list can be updated.
*
* @return {@code true} if the attachment list can be updated, {@code false}
* otherwise.
*/
public boolean canUpdateAttachmentList() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
import org.exoplatform.commons.file.model.FileInfo;
import org.exoplatform.services.security.Identity;
import org.exoplatform.services.security.IdentityRegistry;
import org.exoplatform.social.attachment.model.FileAttachmentResourceList;
import org.exoplatform.social.attachment.model.ObjectAttachmentDetail;
import org.exoplatform.social.attachment.model.ObjectAttachmentList;
import org.exoplatform.social.attachment.model.ObjectAttachmentOperationReport;
import org.exoplatform.social.attachment.model.UploadedAttachmentDetail;
import org.exoplatform.social.attachment.model.*;
import org.exoplatform.social.common.ObjectAlreadyExistsException;
import org.exoplatform.social.metadata.model.MetadataType;

Expand Down Expand Up @@ -93,6 +89,21 @@ void saveAttachment(UploadedAttachmentDetail uploadedAttachmentDetail,
long userIdentityId) throws IOException, ObjectAlreadyExistsException, ObjectNotFoundException;

/**
* Creates an attachment associated with a specific object.
*
* @param objectType The type of the object to which the attachment belongs.
* @param objectId The unique identifier of the object.
* @param attachmentObject The attachment details, including metadata and file
* information.
* @param userAclIdentity The identity acl of the user creating the attachment.
* @return {@link ObjectAttachmentDetail}
*/
ObjectAttachmentDetail createAttachment(String objectType,
String objectId,
FileAttachmentObject attachmentObject,
Identity userAclIdentity) throws ObjectNotFoundException, IllegalAccessException;

/**
* Delete attachments of a given object identified by its type and id
*
* @param objectType object type, can be of any type: activity, comment,
Expand All @@ -111,30 +122,6 @@ void saveAttachment(UploadedAttachmentDetail uploadedAttachmentDetail,
*/
void deleteAttachment(String objectType, String objectId, String fileId);

/**
* Retrieves the list of attachments of a given object identified by its id
*
* @param objectType object type, can be of any type: activity,
* comment, notes...
* @param objectId object technical unique identifier
* @param userAclIdentity user ACL identity retrieved used
* {@link IdentityRegistry}
* @return {@link ObjectAttachmentList} with the list
* of attached files. If no attached files, it
* will return an object containing empty list
* @throws IllegalAccessException when user identified by its
* {@link org.exoplatform.social.core.identity.model.Identity}
* id doesn't have "read" permission of
* selected object
* @throws ObjectNotFoundException when the object identified by its id in
* {@link FileAttachmentResourceList}
* doesn't exists
*/
ObjectAttachmentList getAttachments(String objectType,
String objectId,
Identity userAclIdentity) throws ObjectNotFoundException,
IllegalAccessException;

/**
* Retrieves the list of attachments of a given object identified by its id
*
Expand All @@ -148,6 +135,37 @@ ObjectAttachmentList getAttachments(String objectType,
ObjectAttachmentList getAttachments(String objectType,
String objectId);

/**
* Retrieves a list of {@link ObjectAttachmentDetail} objects associated with a
* specific object type and object ID, with metadata enrichment based on the
* given user's access identity.The result is paginated based on the provided
* offset and limit.
* <p>
* If no attachments are found, an empty {@link ObjectAttachmentList} is
* returned. If the user does not have the necessary access permissions, an
* {@link IllegalAccessException} will be thrown.
* </p>
*
* @param objectType The type of the object associated with the attachments.
* @param objectId The unique ID of the object associated with the attachments.
* @param userAclIdentity The identity of the user requesting the attachments,
* used for access control checks.
* @param offset The offset to be used for pagination (zero-based index).
* @param limit The maximum number of items to return (for pagination).
* @return {@link ObjectAttachmentList} A list of attachments associated with
* the specified object type and object ID, enriched with metadata
* (e.g., alt text and format) where applicable.
* @throws ObjectNotFoundException If the object associated with the provided
* object ID does not exist.
* @throws IllegalAccessException If the user does not have the necessary
* permissions to access the requested attachments.
*/
ObjectAttachmentList getAttachments(String objectType,
String objectId,
Identity userAclIdentity,
int offset,
int limit) throws ObjectNotFoundException, IllegalAccessException;

/**
* @param objectType object type, can be of any type: activity, comment,
* notes...
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2025 Meeds Association [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

package org.exoplatform.social.attachment.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class FileAttachmentResource {

private FileAttachmentObject fileAttachmentObject;

private String objectType;

private String objectId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,21 @@ List<MetadataItem> shareMetadataItemsByObject(MetadataObject sourceObject,
*/
List<String> getMetadataNamesByMetadataTypeAndObject(String metadataTypeName, String objectType, String objectId);

/**
* Retrieves list of metadata names associated with a specific metadata type,
* object type, and object ID.
*
* @param metadataTypeName The name of the metadata type used to filter the results.
* @param objectType The type of the object that the metadata is associated with.
* @param objectId The unique identifier of the object to filter the metadata by.
* @param offset The number of records to skip before starting to return results (used for pagination).
* @param limit The maximum number of results to return (used for pagination).
* @return A {@link List} of {@link String} containing the metadata names associated with the specified
* metadata type, object type, and object ID, sorted in descending order by the metadata ID.
*/
List<String> getMetadataNamesByMetadataTypeAndObject(String metadataTypeName, String objectType, String objectId, int offset, int limit);


/**
* Retrieves the list of Metadata attached to an object identified by its name
* and identifier
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* This file is part of the Meeds project (https://meeds.io/).
*
* Copyright (C) 2025 Meeds Association [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.meeds.social.image.plugin;

import org.exoplatform.commons.exception.ObjectNotFoundException;
import org.exoplatform.portal.config.UserACL;
import org.exoplatform.services.security.Identity;
import org.exoplatform.social.attachment.AttachmentPlugin;

public class PublicImageAttachmentPlugin extends AttachmentPlugin {

private final UserACL userAcl;

private static final String OBJECT_TYPE = "public";

public PublicImageAttachmentPlugin(UserACL userACL) {
this.userAcl = userACL;
}

@Override
public String getObjectType() {
return OBJECT_TYPE;
}

@Override
public boolean hasAccessPermission(Identity userIdentity, String entityId) throws ObjectNotFoundException {
return true;
}

@Override
public boolean hasEditPermission(Identity userIdentity, String entityId) throws ObjectNotFoundException {
return userIdentity != null && userAcl.isAdministrator(userIdentity);
}

@Override
public long getAudienceId(String objectId) throws ObjectNotFoundException {
return 0;
}

@Override
public long getSpaceId(String objectId) throws ObjectNotFoundException {
return 0;
}

@Override
public boolean canUpdateAttachmentList() {
return false;
}
}
Loading

0 comments on commit f2f71c6

Please sign in to comment.