Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public Announcement updateAnnouncement(int RowId, Container c, User u, String ti
}

@Override
public int updateContainer(List<String> discussionSrcIds, Container targetContainer, User u)
public Map<String, Integer> updateContainer(List<String> discussionSrcIds, Container targetContainer, User u)
{
return AnnouncementManager.updateContainer(discussionSrcIds, targetContainer, u);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,15 @@ public static AnnouncementModel updateAnnouncement(User user, AnnouncementModel
return result;
}

public static int updateContainer(List<String> discussionSrcIds, Container targetContainer, User user)
public static Map<String, Integer> updateContainer(List<String> discussionSrcIds, Container targetContainer, User user)
{
return Table.updateContainer(_comm.getTableInfoAnnouncements(), "discussionSrcIdentifier", discussionSrcIds, targetContainer, user, false);
// move the attachments associated with the comments
SimpleFilter filter = new SimpleFilter(FieldKey.fromParts("discussionSrcIdentifier"), discussionSrcIds, CompareType.IN);
TableSelector selector = new TableSelector(_comm.getTableInfoAnnouncements(), Collections.singleton("entityId"), filter, null);
Map<String, Integer> updateCounts = new HashMap<>();
updateCounts.put("attachments", Table.updateContainer(_core.getTableInfoDocuments(), "parent", selector.getArrayList(String.class), targetContainer, user, false));
updateCounts.put("announcements", Table.updateContainer(_comm.getTableInfoAnnouncements(), "discussionSrcIdentifier", discussionSrcIds, targetContainer, user, false));
return updateCounts;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import java.util.Collection;
import java.util.List;
import java.util.Map;

public interface AnnouncementService
{
Expand Down Expand Up @@ -61,8 +62,8 @@ Announcement insertAnnouncement(Container container, User u, String title, Strin
// Update
Announcement updateAnnouncement(int RowId, Container c, User u, String title, String body);

// move announcements to the given target container
int updateContainer(List<String> discussionSrcIds, Container targetContainer, User u);
// move announcements and their attachments to the given target container
Map<String, Integer> updateContainer(List<String> discussionSrcIds, Container targetContainer, User u);

// Delete
void deleteAnnouncement(Announcement announcement);
Expand Down
11 changes: 7 additions & 4 deletions api/src/org/labkey/api/data/ContainerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.labkey.api.security.permissions.InsertPermission;
import org.labkey.api.security.permissions.Permission;
import org.labkey.api.security.permissions.ReadPermission;
import org.labkey.api.security.permissions.SampleWorkflowJobPermission;
import org.labkey.api.security.roles.AuthorRole;
import org.labkey.api.security.roles.ReaderRole;
import org.labkey.api.security.roles.Role;
Expand Down Expand Up @@ -2605,7 +2606,7 @@ private static Container getForPathAlias(String path)
return ret.length == 0 ? null : ret[0];
}

public static Container getMoveTargetContainer(@Nullable String queryName, @NotNull Container sourceContainer, User user, @Nullable String targetIdOrPath, Errors errors)
public static Container getMoveTargetContainer(String schemaName, @Nullable String queryName, @NotNull Container sourceContainer, User user, @Nullable String targetIdOrPath, Errors errors)
{
if (targetIdOrPath == null)
{
Expand All @@ -2620,11 +2621,13 @@ public static Container getMoveTargetContainer(@Nullable String queryName, @NotN
return null;
}

if (!_targetContainer.hasPermission(user, InsertPermission.class))
Class<? extends Permission> permClass = InsertPermission.class;
if (schemaName != null && schemaName.equalsIgnoreCase("workflow") && queryName != null && queryName.equalsIgnoreCase("job"))
permClass = SampleWorkflowJobPermission.class;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is a bit of a hack and am open to other ideas.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only called from the MoveRowsAction, there really isn't a better, workflow specific location for this code. One idea would be to pass in the permClass to this method so that it is the MoveRowsAction.validateForm which has this workflow specific code in it instead of the ContainerManager (but that is minor).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a bad idea, but only marginally better, so I'm leaving as is for now.

if (!_targetContainer.hasPermission(user, permClass))
{
String _queryName = queryName == null ? "this table" : "'" + queryName + "'";
errors.reject(ERROR_GENERIC, "You do not have permission to move rows from " + _queryName + " to the target container: " + targetIdOrPath + ".");
return null;
throw new UnauthorizedException("You do not have permission to move rows from " + _queryName + " to the target container: " + targetIdOrPath + ".");
}

if (!isValidTargetContainer(sourceContainer, _targetContainer))
Expand Down
7 changes: 6 additions & 1 deletion api/src/org/labkey/api/exp/OntologyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,12 @@ public static void updateObjectPropertyOrder(User user, Container container, Str
*/
public static int updateContainer(Container targetContainer, User user, @NotNull String objectLSID)
{
return Table.updateContainer(getTinfoObject(), "objectURI", List.of(objectLSID), targetContainer, user, false);
return updateContainer(targetContainer, user, List.of(objectLSID));
}

public static int updateContainer(Container targetContainer, User user, @NotNull List<String> objectLSIDs)
{
return Table.updateContainer(getTinfoObject(), "objectURI", objectLSIDs, targetContainer, user, false);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion query/src/org/labkey/query/controllers/QueryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4968,7 +4968,8 @@ public void validateForm(MoveRowsForm form, Errors errors)
else
{
String queryName = json.optString(PROP_QUERY_NAME, null);
_targetContainer = ContainerManager.getMoveTargetContainer(queryName, getContainer(), getUser(), getTargetContainerProp(), errors);
String schemaName = json.optString(PROP_SCHEMA_NAME, null);
_targetContainer = ContainerManager.getMoveTargetContainer(schemaName, queryName, getContainer(), getUser(), getTargetContainerProp(), errors);
}
}
}
Expand Down