Skip to content

Commit 18bdc2f

Browse files
committed
Drop states for folder items
1 parent 4169f80 commit 18bdc2f

File tree

10 files changed

+46
-38
lines changed

10 files changed

+46
-38
lines changed

src/main/java/org/craftercms/studio/api/v2/dal/Item.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
2+
* Copyright (C) 2007-2025 Crafter Software Corporation. All Rights Reserved.
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License version 3 as published by
@@ -18,12 +18,14 @@
1818

1919
import org.apache.commons.io.FilenameUtils;
2020
import org.apache.commons.lang3.ArrayUtils;
21+
import org.craftercms.studio.api.v1.constant.StudioConstants;
2122
import org.craftercms.studio.model.rest.Person;
2223
import org.slf4j.Logger;
2324
import org.slf4j.LoggerFactory;
2425

2526
import java.time.ZonedDateTime;
2627

28+
import static org.craftercms.studio.api.v1.constant.StudioConstants.CONTENT_TYPE_FOLDER;
2729
import static org.craftercms.studio.impl.v1.repository.git.GitContentRepositoryConstants.IGNORE_FILES;
2830

2931
public class Item {
@@ -134,7 +136,7 @@ public void setPreviewUrl(String previewUrl) {
134136
}
135137

136138
public long getState() {
137-
return state;
139+
return CONTENT_TYPE_FOLDER.equals(systemType) ? 0 : state;
138140
}
139141

140142
public void setState(long state) {

src/main/java/org/craftercms/studio/api/v2/security/ContentItemPossibleActionsConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public final class ContentItemPossibleActionsConstants {
8383
public static final long CONFIGURATION = PUBLISH + PUBLISH_REQUEST;
8484

8585
public static final long FOLDER = CONTENT_COPY + CONTENT_CREATE + CONTENT_PASTE + CONTENT_RENAME + CONTENT_CUT +
86-
CONTENT_UPLOAD + FOLDER_CREATE + CONTENT_DELETE + ITEM_UNLOCK;
86+
CONTENT_UPLOAD + FOLDER_CREATE + CONTENT_DELETE;
8787

8888
public static final long USER = 0L;
8989

src/main/java/org/craftercms/studio/api/v2/security/SemanticsAvailableActionsResolver.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
2+
* Copyright (C) 2007-2025 Crafter Software Corporation. All Rights Reserved.
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License version 3 as published by
@@ -18,7 +18,6 @@
1818

1919
import org.craftercms.studio.api.v1.exception.ServiceLayerException;
2020
import org.craftercms.studio.api.v1.exception.security.UserNotFoundException;
21-
import org.craftercms.studio.api.v2.dal.Item;
2221
import org.craftercms.studio.api.v2.dal.item.ContentItem;
2322

2423
/**
@@ -28,17 +27,6 @@
2827
*/
2928
public interface SemanticsAvailableActionsResolver {
3029

31-
/**
32-
* Calculate available actions for given content item
33-
*
34-
* @param username user name to apply permissions
35-
* @param siteId site identifier
36-
* @param item Item
37-
* @return bitmap representing available actions
38-
*/
39-
long calculateContentItemAvailableActions(String username, String siteId, Item item)
40-
throws ServiceLayerException, UserNotFoundException;
41-
4230
/**
4331
* Calculate available actions for given content item
4432
*
@@ -48,5 +36,5 @@ long calculateContentItemAvailableActions(String username, String siteId, Item i
4836
* @return bitmap representing available actions
4937
*/
5038
long calculateContentItemAvailableActions(String username, String siteId, ContentItem detailedItem)
51-
throws ServiceLayerException, UserNotFoundException;
39+
throws ServiceLayerException, UserNotFoundException;
5240
}

src/main/java/org/craftercms/studio/impl/v1/service/site/SiteServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ private void processCreatedDirectory(ItemDAO itemDao, String siteId, String dire
347347
String label = new File(directory).getName();
348348
Item item = itemService.instantiateItem(siteId, directory)
349349
.withPreviewUrl(null)
350-
.withState(NEW.value)
350+
.withState(0)
351351
.withLockedBy(null)
352352
.withCreatedBy(userId)
353353
.withCreatedOn(now)

src/main/java/org/craftercms/studio/impl/v2/security/SemanticsAvailableActionsResolverImpl.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.craftercms.studio.api.v1.exception.SiteNotFoundException;
2424
import org.craftercms.studio.api.v1.exception.security.UserNotFoundException;
2525
import org.craftercms.studio.api.v1.service.configuration.ServicesConfig;
26-
import org.craftercms.studio.api.v2.dal.Item;
2726
import org.craftercms.studio.api.v2.dal.ItemState;
2827
import org.craftercms.studio.api.v2.dal.item.ContentItem;
2928
import org.craftercms.studio.api.v2.repository.blob.StudioBlobStore;
@@ -63,28 +62,20 @@ public class SemanticsAvailableActionsResolverImpl implements SemanticsAvailable
6362
private StudioBlobStoreResolver studioBlobStoreResolver;
6463
private ContentTypeService contentTypeService;
6564

66-
@Override
67-
public long calculateContentItemAvailableActions(String username, String siteId, Item item)
68-
throws ServiceLayerException, UserNotFoundException {
69-
long userPermissionsBitmap = availableActionsResolver.getContentItemAvailableActions(username, siteId, item.getPath());
70-
long systemTypeBitmap = getPossibleActionsForObject(item.getSystemType());
71-
long workflowStateBitmap = getPossibleActionsForItemState(item.getState(),
72-
hasUnlockPermission(item.getLockOwner(), item.getState(), siteId, item.getPath(), username));
73-
74-
long result = (userPermissionsBitmap & systemTypeBitmap) & workflowStateBitmap;
75-
return applySpecialUseCaseFilters(username, siteId, item.getPath(), item.getMimeType(),
76-
item.getSystemType(), item.getContentTypeId(), item.getState(), result);
77-
}
78-
7965
@Override
8066
public long calculateContentItemAvailableActions(String username, String siteId, ContentItem detailedItem)
8167
throws ServiceLayerException, UserNotFoundException {
8268
long userPermissionsBitmap = availableActionsResolver.getContentItemAvailableActions(username, siteId, detailedItem.getPath());
8369
long systemTypeBitmap = getPossibleActionsForObject(detailedItem.getSystemType());
84-
long workflowStateBitmap = getPossibleActionsForItemState(detailedItem.getState(),
85-
hasUnlockPermission(detailedItem.getLockOwner(), detailedItem.getState(), siteId, detailedItem.getPath(), username));
8670

87-
long result = (userPermissionsBitmap & systemTypeBitmap) & workflowStateBitmap;
71+
long result = userPermissionsBitmap & systemTypeBitmap;
72+
if (!CONTENT_TYPE_FOLDER.equals(detailedItem.getSystemType())) {
73+
long workflowStateBitmap = getPossibleActionsForItemState(detailedItem.getState(),
74+
hasUnlockPermission(detailedItem.getLockOwner(), detailedItem.getState(), siteId, detailedItem.getPath(), username));
75+
76+
result &= workflowStateBitmap;
77+
}
78+
8879
return applySpecialUseCaseFilters(username, siteId, detailedItem.getPath(), detailedItem.getMimeType(),
8980
detailedItem.getSystemType(), detailedItem.getContentTypeId(),
9081
detailedItem.getState(),

src/main/java/org/craftercms/studio/impl/v2/service/item/internal/ItemServiceInternalImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public void persistItemAfterCreateFolder(String siteId, String folderPath, Strin
281281
.withParentId(parentId)
282282
.build();
283283
item.setState(ItemState.savedAndClosed(item.getState()));
284-
item.setSystemType("folder");
284+
item.setSystemType(CONTENT_TYPE_FOLDER);
285285
upsertEntry(item);
286286
}
287287

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (C) 2007-2025 Crafter Software Corporation. All Rights Reserved.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 3 as published by
6+
* the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
UPDATE item SET state = 0 WHERE system_type = 'folder' ;
18+
19+
UPDATE `_meta` SET `version` = '5.0.0.6' ;

src/main/resources/crafter/studio/upgrade/pipelines.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,11 @@ pipelines:
800800
operations:
801801
- type: dbScriptUpgrader
802802
filename: upgrade/5.0.x/5.0.0.4-to-5.0.0.5.sql
803+
- currentVersion: 5.0.0.5
804+
nextVersion: 5.0.0.6
805+
operations:
806+
- type: dbScriptUpgrader
807+
filename: upgrade/5.0.x/5.0.0.5-to-5.0.0.6.sql
803808

804809
# Pipeline to upgrade site repositories
805810
site:

src/main/resources/org/craftercms/studio/api/v2/dal/ItemDAO.xml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@
372372
<update id="moveItemInternal">
373373
UPDATE item i INNER JOIN site s ON i.site_id = s.id
374374
SET path = #{newPath},
375-
i.state = (i.state | #{onStatesBitMap}) &amp; ~#{offStatesBitMap},
375+
i.state = CASE WHEN i.system_type = '${systemTypeFolder}' THEN 0 ELSE (i.state | #{onStatesBitMap}) &amp; ~#{offStatesBitMap} END,
376376
i.preview_url = IF(i.system_type = '${systemTypeFolder}', NULL, #{newPreviewUrl}),
377377
i.last_modified_by = #{userId},
378378
i.last_modified_on = NOW()
@@ -389,7 +389,9 @@
389389
INSERT INTO item (site_id, path, preview_url, state, locked_by, created_by, created_on, last_modified_by,
390390
last_modified_on, label, content_type_id, system_type, mime_type, locale_code,
391391
translation_source_id, size, parent_id, ignored)
392-
SELECT s.id, #{newPath} AS path, IF(i.system_type = '${systemTypeFolder}', NULL, #{previewUrl}) AS preview_url, ${state}, null, ${userId}, NOW(), ${userId},
392+
SELECT s.id, #{newPath} AS path, IF(i.system_type = '${systemTypeFolder}', NULL, #{previewUrl}) AS preview_url,
393+
CASE WHEN i.system_type = '${systemTypeFolder}' THEN 0 ELSE ${state} END,
394+
null, ${userId}, NOW(), ${userId},
393395
NOW(), IFNULL(#{label}, i.label) AS label, i.content_type_id, i.system_type, i.mime_type, i.locale_code,
394396
i.translation_source_id, i.size, #{parentId}, i.ignored
395397
FROM item i INNER JOIN site s ON i.site_id = s.id

src/main/resources/org/craftercms/studio/api/v2/dal/publish/PublishDAO.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
) AS updates
155155
SET item.state = (item.state | updates.maskOn) &amp; ~updates.maskOff
156156
WHERE item.id = updates.item_id
157+
AND item.system_type &lt;&gt; '${systemTypeFolder}'
157158
</update>
158159

159160
<insert id="insertItemPublishItems">

0 commit comments

Comments
 (0)