Skip to content

Commit 346471c

Browse files
committed
changes per core call
1 parent 9d5a938 commit 346471c

File tree

2 files changed

+60
-47
lines changed

2 files changed

+60
-47
lines changed

content/content-tool/tool/src/java/org/sakaiproject/content/tool/ResourcesAction.java

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ public void setParent(String parent)
827827

828828
/** vm files for each mode. */
829829
private static final String TEMPLATE_DAV = "content/chef_resources_webdav";
830-
830+
831831
private static final String TEMPLATE_QUOTA = "resources/sakai_quota";
832832

833833
private static final String TEMPLATE_DELETE_CONFIRM = "content/chef_resources_deleteConfirm";
@@ -3802,17 +3802,17 @@ public String buildColumnsContext(VelocityPortlet portlet, Context context, RunD
38023802

38033803
}
38043804
catch (IdUnusedException e)
3805-
{
3805+
{
38063806
// TODO Auto-generated catch block
38073807
log.warn("IdUnusedException {}", e.getMessage());
38083808
}
38093809
catch (TypeException e)
3810-
{
3810+
{
38113811
// TODO Auto-generated catch block
38123812
log.warn("TypeException {}", e.getMessage());
38133813
}
38143814
catch (PermissionException e)
3815-
{
3815+
{
38163816
// TODO Auto-generated catch block
38173817
log.warn("PermissionException {}", e.getMessage());
38183818
}
@@ -4869,15 +4869,15 @@ public String buildPermissionsPageContext(VelocityPortlet portlet, Context conte
48694869
log.debug("{}.buildPermissionsPageContext()", this);
48704870

48714871
String reference = (String) state.getAttribute("folder_group_reference");
4872+
String overrideReference = null;
4873+
if (StringUtils.isNotBlank(reference)) {
4874+
overrideReference = contentHostingService.getContainingCollectionId(reference);
4875+
}
48724876

4873-
String siteId = toolManager.getCurrentPlacement().getContext();
4874-
4875-
String siteCollectionId = contentHostingService.getSiteCollection(siteId);
4876-
String overrideReference = contentHostingService.getReference(siteCollectionId);
48774877
String folderName = (String) state.getAttribute("folder_name");
48784878
if (StringUtils.isNoneBlank(reference, folderName)) {
48794879
context.put("reference", reference);
4880-
if (!reference.equals(overrideReference)) {
4880+
if (overrideReference != null && !reference.equals(overrideReference)) {
48814881
context.put("overrideReference", overrideReference);
48824882
}
48834883
context.put("folderName", folderName);
@@ -4890,7 +4890,7 @@ public String buildPermissionsPageContext(VelocityPortlet portlet, Context conte
48904890
context.put("permissionsLabel", rb.getString("list.fPerm"));
48914891

48924892
String toolId = toolManager.getCurrentPlacement().getId();
4893-
String startUrl = ServerConfigurationService.getPortalUrl() + "/site/" + siteId + "/tool/" + toolId + "?panel=Main";
4893+
String startUrl = ServerConfigurationService.getPortalUrl() + "/site/" + toolManager.getCurrentPlacement().getContext() + "/tool/" + toolId + "?panel=Main";
48944894
context.put("startPage", startUrl);
48954895

48964896
state.setAttribute (STATE_MODE, MODE_LIST);
@@ -5720,7 +5720,7 @@ public String buildQuotaContext( VelocityPortlet portlet,
57205720
* Iterate over attributes in ToolSession and remove all attributes starting with a particular prefix.
57215721
* @param toolSession
57225722
* @param prefix
5723-
*/
5723+
*/
57245724
protected void cleanup(ToolSession toolSession, String prefix)
57255725
{
57265726
log.debug("{}.cleanup()", this);
@@ -6991,32 +6991,6 @@ public void doHierarchy(RunData data)
69916991
state.setAttribute(STATE_LIST_PREFERENCE, LIST_HIERARCHY);
69926992
}
69936993

6994-
// private static void resetCurrentMode(SessionState state)
6995-
// {
6996-
// String mode = (String) state.getAttribute(STATE_MODE);
6997-
// if(isStackEmpty(state))
6998-
// {
6999-
// if(MODE_HELPER.equals(mode))
7000-
// {
7001-
// cleanupState(state);
7002-
// state.setAttribute(STATE_RESOURCES_HELPER_MODE, MODE_ATTACHMENT_DONE);
7003-
// }
7004-
// else
7005-
// {
7006-
// state.setAttribute(STATE_MODE, MODE_LIST);
7007-
// state.removeAttribute(STATE_RESOURCES_HELPER_MODE);
7008-
// }
7009-
// return;
7010-
// }
7011-
// Map current_stack_frame = peekAtStack(state);
7012-
// String helper_mode = (String) current_stack_frame.get(STATE_RESOURCES_HELPER_MODE);
7013-
// if(helper_mode != null)
7014-
// {
7015-
// state.setAttribute(STATE_RESOURCES_HELPER_MODE, helper_mode);
7016-
// }
7017-
//
7018-
// }
7019-
//
70206994
/**
70216995
* Expand all the collection resources and put in EXPANDED_COLLECTIONS attribute.
70226996
*/

webapi/src/main/java/org/sakaiproject/webapi/controllers/PermissionsController.java

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,64 @@ public Map<String, Object> getPermissions(@PathVariable String siteId, @PathVari
8383

8484
Site site = getSiteById(siteId);
8585

86+
// Get the site's AuthzGroup once for potential reuse
87+
AuthzGroup siteAuthzGroup;
88+
try {
89+
siteAuthzGroup = authzGroupService.getAuthzGroup(siteRef);
90+
} catch (GroupNotDefinedException ex) {
91+
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No site realm defined for ref " + siteRef);
92+
}
93+
8694
AuthzGroup authzGroup;
8795
try {
8896
authzGroup = authzGroupService.getAuthzGroup(ref);
8997
} catch (GroupNotDefinedException e) {
9098
// Instructor editing a folder that doesn't have a realm yet
91-
try {
92-
authzGroup = authzGroupService.getAuthzGroup(siteRef);
93-
} catch (GroupNotDefinedException ex) {
94-
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "No realm defined for ref " + siteRef);
95-
}
99+
authzGroup = siteAuthzGroup;
96100
}
97101

98102
AuthzGroup overrideAuthzGroup = null;
99103
if (StringUtils.isNotBlank(overrideRef)) {
100-
try {
101-
overrideAuthzGroup = authzGroupService.getAuthzGroup(overrideRef);
102-
} catch (GroupNotDefinedException e) {
103-
// Instructor editing a folder that doesn't have a realm yet
104-
overrideAuthzGroup = authzGroup;
104+
String tempOverrideRef = overrideRef;
105+
boolean done = false;
106+
// We need to make sure the ref is for a content folder in this site
107+
if (tempOverrideRef.matches("^/content/(group|group-user)/" + siteId + "/.*")) {
108+
// Keep trying parent folders until we find one with permissions or reach site level
109+
while (!done) {
110+
try {
111+
overrideAuthzGroup = authzGroupService.getAuthzGroup(tempOverrideRef);
112+
done = true;
113+
} catch (GroupNotDefinedException e) {
114+
// Try parent folder - first check if we're already at site level
115+
String siteRoot = "/content/group/" + siteId + "/";
116+
String siteUserRoot = "/content/group-user/" + siteId + "/";
117+
if (tempOverrideRef.equals(siteRoot) || tempOverrideRef.equals(siteUserRoot)) {
118+
// At site level, use site's AuthzGroup
119+
overrideAuthzGroup = siteAuthzGroup;
120+
done = true;
121+
} else {
122+
// Remove the last folder segment but preserve trailing slash
123+
String path = tempOverrideRef.substring(0, tempOverrideRef.length() - 1); // remove trailing slash
124+
int lastSlash = path.lastIndexOf('/');
125+
if (lastSlash > 0) {
126+
tempOverrideRef = path.substring(0, lastSlash + 1); // restore trailing slash
127+
log.debug("Trying parent folder for permissions: {}", tempOverrideRef);
128+
} else {
129+
// Shouldn't happen with our path pattern, but just in case
130+
overrideAuthzGroup = siteAuthzGroup;
131+
done = true;
132+
}
133+
}
134+
}
135+
}
136+
} else {
137+
// Not a content path, try it directly once
138+
try {
139+
overrideAuthzGroup = authzGroupService.getAuthzGroup(tempOverrideRef);
140+
} catch (GroupNotDefinedException e) {
141+
// Use site's AuthzGroup
142+
overrideAuthzGroup = siteAuthzGroup;
143+
}
105144
}
106145
}
107146

0 commit comments

Comments
 (0)