Skip to content

Commit

Permalink
Allow element description modification (#109)
Browse files Browse the repository at this point in the history
Signed-off-by: Seddik Yengui <seddik.yengui@rte-france.com>
  • Loading branch information
YenguiSeddik authored Jan 10, 2024
1 parent 06e8024 commit 1de2b97
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class DirectoryElementEntity {
@Column(name = "owner", length = 80, nullable = false)
private String owner;

@Column(name = "description")
@Column(name = "description", columnDefinition = "CLOB")
private String description;

@Column(name = "creationDate")
Expand All @@ -68,11 +68,16 @@ public DirectoryElementEntity update(@NonNull ElementAttributes newElementAttrib
this.isPrivate = newElementAttributes.getAccessRights().isPrivate();
}

if (Objects.nonNull(newElementAttributes.getDescription())) {
this.description = newElementAttributes.getDescription();
}

return this;
}

public boolean isAttributesUpdatable(@NonNull ElementAttributes newElementAttributes, String userId) {
return (// Updatable attributes
Objects.nonNull(newElementAttributes.getDescription()) ||
StringUtils.isNotBlank(newElementAttributes.getElementName()) ||
//Only the owner can update the accessRights of a directory (to avoid user locking themselves out of a directory they don't own
type.equals(DIRECTORY) && Objects.nonNull(newElementAttributes.getAccessRights()) && userId.equals(owner))
Expand All @@ -81,7 +86,6 @@ public boolean isAttributesUpdatable(@NonNull ElementAttributes newElementAttrib
Objects.isNull(newElementAttributes.getType()) &&
Objects.isNull(newElementAttributes.getOwner()) &&
Objects.isNull(newElementAttributes.getSubdirectoriesCount()) &&
Objects.isNull(newElementAttributes.getDescription()) &&
Objects.isNull(newElementAttributes.getCreationDate()) &&
Objects.isNull(newElementAttributes.getLastModificationDate()) &&
Objects.isNull(newElementAttributes.getLastModifiedBy());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">
<changeSet author="yenguised (generated)" id="1704461075576-1">
<modifyDataType tableName="element" columnName="description" newDataType="CLOB"/>
</changeSet>
</databaseChangeLog>
6 changes: 5 additions & 1 deletion src/main/resources/db/changelog/db.changelog-master.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ databaseChangeLog:

- include:
file: changesets/changelog_20221122T140541Z.xml
relativeToChangelogFile: true
relativeToChangelogFile: true

- include:
file: changesets/changelog_20240105T132426Z.xml
relativeToChangelogFile: true
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ public void testElementEntityUpdate() {

assertTrue(elementEntity.isAttributesUpdatable(ElementAttributes.builder().elementName("newName").build(), "userId"));
assertTrue(elementEntity.isAttributesUpdatable(ElementAttributes.builder().accessRights(new AccessRightsAttributes(false)).build(), "userId"));
assertTrue(elementEntity.isAttributesUpdatable(ElementAttributes.builder().description("newDescription").build(), "userId"));

assertFalse(elementEntity.isAttributesUpdatable(ElementAttributes.builder().accessRights(new AccessRightsAttributes(false)).build(), "userId2"));
assertFalse(elementEntity.isAttributesUpdatable(ElementAttributes.builder().elementUuid(UUID.randomUUID()).build(), "userId"));
assertFalse(elementEntity.isAttributesUpdatable(ElementAttributes.builder().type(STUDY).build(), "userId"));
assertFalse(elementEntity.isAttributesUpdatable(ElementAttributes.builder().owner("newUser").build(), "userId"));
assertFalse(elementEntity.isAttributesUpdatable(ElementAttributes.builder().subdirectoriesCount(1L).build(), "userId"));
assertFalse(elementEntity.isAttributesUpdatable(ElementAttributes.builder().description("newDescription").build(), "userId"));

assertFalse(elementEntity2.isAttributesUpdatable(ElementAttributes.builder().accessRights(new AccessRightsAttributes(false)).build(), "userId"));

Expand Down

0 comments on commit 1de2b97

Please sign in to comment.