Author: ktlili
Date: Tue Jun 19 17:03:37 2007
New Revision: 17647
URL: https://svndev.jahia.net/websvn/listing.php?sc=3D1&rev=3D17647&repname=
=3Djahia
Log:
- add "unselect portlet" feature (PORTAL-120, only SP)
- fix acl bug with portlet: allow a user to update portlet if he's got R/W =
acces on field (PORTAL-122)
Modified:
branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/engines/shared/App=
lication_Field.java
Modified: branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/engines/shar=
ed/Application_Field.java
URL: https://svndev.jahia.net/websvn/diff.php?path=3D/branches/JAHIA-5-0-SP=
-BRANCH/core/src/java/org/jahia/engines/shared/Application_Field.java&rev=
=3D17647&repname=3Djahia
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/engines/shared/App=
lication_Field.java (original)
+++ branches/JAHIA-5-0-SP-BRANCH/core/src/java/org/jahia/engines/shared/App=
lication_Field.java Tue Jun 19 17:03:37 2007
@@ -115,7 +115,7 @@
*/
private boolean getFormData(ProcessingContext jParams, Map engineMap, =
JahiaField theField)
throws JahiaException {
-
+ logger.debug("getFormaData()");
String fieldValue =3D jParams.getParameter("_" + Integer.toString(=
theField.getID()));
=
if (fieldValue !=3D null) {
@@ -124,23 +124,28 @@
=
Integer oldAppID =3D (Integer) engineMap.get(theField.getDefinitio=
n().getName() + "_appID");
if ((oldAppID =3D=3D null) || (oldAppID.intValue() =3D=3D -1)) {
- return true;
- }
- WebAppContext appContext =3D ServicesRegistry.getInstance()
- .getApplicationsManagerService()
- .getApplicationContext(oldAppID.intValue());
- Vector roles =3D appContext.getRoles();
- // Handle roles changes
- ArrayList roleMembersList =3D new ArrayList();
- if (roles !=3D null) {
- String role =3D null;
- for (int roleNb =3D 0; roleNb < roles.size(); roleNb++) {
- HashSet roleMembers =3D getFormMembers(jParams, roleNb);
- roleMembersList.add(roleMembers);
+ logger.debug("No webapp was selected.");
+ //return true;
+ }else{
+ =
+ WebAppContext appContext =3D ServicesRegistry.getInstance()
+ .getApplicationsManagerService()
+ .getApplicationContext(oldAppID.intValue());
+ Vector roles =3D appContext.getRoles();
+ // Handle roles changes
+ ArrayList roleMembersList =3D new ArrayList();
+ if (roles !=3D null) {
+ String role =3D null;
+ for (int roleNb =3D 0; roleNb < roles.size(); roleNb++) {
+ HashSet roleMembers =3D getFormMembers(jParams, roleNb=
);
+ roleMembersList.add(roleMembers);
+ }
}
+ appRoleMembers.put(oldAppID, roleMembersList);
+ engineMap.put(APPLICATION_ROLES, appRoleMembers);
}
- appRoleMembers.put(oldAppID, roleMembersList);
- engineMap.put(APPLICATION_ROLES, appRoleMembers);
+
+ // update engineMap values for selected webapp from field value
if (fieldValue !=3D null) {
int separatorPos =3D fieldValue.indexOf("_");
if (separatorPos !=3D -1) {
@@ -165,12 +170,12 @@
private boolean isAppSelected(JahiaField theField) {
String selectedEntryPoint =3D (String) theField.getRawValue();
if (selectedEntryPoint =3D=3D null) {
- logger.debug("Not app. selected");
+ logger.debug("No app. selected");
return false;
}
=
- if (selectedEntryPoint.equalsIgnoreCase("")) {
- logger.debug("Not app. selected");
+ if (selectedEntryPoint.equalsIgnoreCase("") || selectedEntryPoint.=
equalsIgnoreCase("-1")) {
+ logger.debug("No app. selected");
return false;
}
int separatorPos =3D selectedEntryPoint.indexOf("_");
@@ -205,7 +210,7 @@
boolean success =3D true;
int selectedAppID =3D -1;
if (engineMap.get("createApplication_" +
- theField.getDefinition().getName()) !=3D null && isAppSele=
cted(theField)) {
+ theField.getDefinition().getName()) !=3D null) {
=
String selectedEntryPoint =3D (String) theField.getRawValue();
int separatorPos =3D selectedEntryPoint.indexOf("_");
@@ -222,6 +227,7 @@
entryPointInstanceID);
int newEntryPointInstanceID =3D -1;
=
+ // remove old entrypointinstance
if (epInstance !=3D null) {
// first let's check if we have selected the same inst=
ance
=
@@ -251,37 +257,42 @@
}
}
=
- ApplicationBean newAppBean =3D ServicesRegistry.getInstanc=
e().
- getApplicationsManagerService().
- getApplication(selectedAppID);
- EntryPointDefinition newEntryPointDefinition =3D null;
- ArrayList epDefinitions =3D newAppBean.getEntryPointDefini=
tions();
- Iterator epDefIter =3D epDefinitions.iterator();
- while (epDefIter.hasNext()) {
- EntryPointDefinition curDef =3D (EntryPointDefinition)
- epDefIter.next();
- if (curDef.getName().equals(selectedEntryPointDefName)=
) {
- newEntryPointDefinition =3D curDef;
- break;
+ // add new entrypointinstance
+ if(isAppSelected(theField)){
+ logger.debug("SelectAppId =3D "+selectedAppID);
+ ApplicationBean newAppBean =3D ServicesRegistry.getIns=
tance().getApplicationsManagerService().getApplication(selectedAppID);
+ EntryPointDefinition newEntryPointDefinition =3D null;
+ ArrayList epDefinitions =3D newAppBean.getEntryPointDe=
finitions();
+ Iterator epDefIter =3D epDefinitions.iterator();
+ while (epDefIter.hasNext()) {
+ EntryPointDefinition curDef =3D (EntryPointDefinit=
ion)
+ epDefIter.next();
+ if (curDef.getName().equals(selectedEntryPointDefN=
ame)) {
+ newEntryPointDefinition =3D curDef;
+ break;
+ }
}
- }
=
- // we need to check here if we need to create a new instan=
ce
- // or if we will just be using an existing one (for example
- // if the user hasn't changed his choice in the case of an
- // update).
- if (newEntryPointInstanceID =3D=3D -1) {
- EntryPointInstance newEPInstance =3D ServicesRegistry.=
getInstance().
- getApplicationsManagerService().
- createEntryPointInstance(
- newEntryPointDefinition);
- if (newEPInstance !=3D null) {
- newEntryPointInstanceID =3D newEPInstance.getID();
+ // we need to check here if we need to create a new in=
stance
+ // or if we will just be using an existing one (for ex=
ample
+ // if the user hasn't changed his choice in the case o=
f an
+ // update).
+ if (newEntryPointInstanceID =3D=3D -1) {
+ EntryPointInstance newEPInstance =3D ServicesRegis=
try.getInstance().
+ getApplicationsManagerService().
+ createEntryPointInstance(
+ newEntryPointDefinition);
+ if (newEPInstance !=3D null) {
+ newEntryPointInstanceID =3D newEPInstance.getI=
D();
+ }
}
- }
=
- if (newEntryPointInstanceID !=3D -1) {
- theField.setValue(Integer.toString(newEntryPointInstan=
ceID));
+ if (newEntryPointInstanceID !=3D -1) {
+ theField.setValue(Integer.toString(newEntryPointIn=
stanceID));
+ }
+ }else{
+ logger.debug("No webapp. selected ste field value to -=
1");
+ theField.setValue("-1");
}
} else {
// this is an uninitialized field, let's keep it that way :
@@ -301,62 +312,65 @@
}
success =3D theField.save(jParams);
=
- WebAppContext appContext =3D ServicesRegistry.getInstance()
+ if(isAppSelected(theField)) {
+ WebAppContext appContext =3D ServicesRegistry.getInstance()
.getApplicationsManagerService()
.getApplicationContext(appID.intValue());
- if (appContext !=3D null) {
- Vector roles =3D appContext.getRoles();
- // Handle roles changes
- if (roles !=3D null) {
- String role =3D null;
- for (int roleNb =3D 0; roleNb < roles.size(); roleNb++=
) {
- role =3D (String) roles.get(roleNb);
- JahiaGroup grp =3D ServicesRegistry.getInstance().
- getJahiaGroupManagerService().
- lookupGroup(0,
+ if (appContext !=3D null) {
+ Vector roles =3D appContext.getRoles();
+ // Handle roles changes
+ if (roles !=3D null) {
+ String role =3D null;
+ for (int roleNb =3D 0; roleNb < roles.size(); role=
Nb++) {
+ role =3D (String) roles.get(roleNb);
+ JahiaGroup grp =3D ServicesRegistry.getInstanc=
e().
+ getJahiaGroupManagerService().
+ lookupGroup(0,
appID + "_" + theField.getID() +
"_" + role);
- if (grp =3D=3D null) {
- // create group
- grp =3D ServicesRegistry.getInstance().
- getJahiaGroupManagerService().
- createGroup(0,
- appID + "_" + theField.getID()=
+ "_" +
+ if (grp =3D=3D null) {
+ // create group
+ grp =3D ServicesRegistry.getInstance().
+ getJahiaGroupManagerService().
+ createGroup(0,
+ appID + "_" + theField.get=
ID() + "_" +
role, new Properties()=
);
- }
- HashSet membersSet =3D getFormMembers(jParams, rol=
eNb);
- Enumeration members =3D grp.members();
- Principal p =3D null;
- while (members.hasMoreElements()) {
- p =3D (Principal) members.nextElement();
- if (p instanceof JahiaUser) {
- if (!membersSet.contains((JahiaUser) p)) {
- logger.debug("removed member=3D" + p.g=
etName());
- grp.removeMember((JahiaUser) p);
- } else {
- membersSet.remove((JahiaUser) p);
- }
- } else if (p instanceof JahiaGroup) {
- if (!membersSet.contains((JahiaGroup) p)) {
- logger.debug("removed member=3D" + p.g=
etName());
- grp.removeMember((JahiaGroup) p);
- } else {
- membersSet.remove((JahiaGroup) p);
+ }
+ HashSet membersSet =3D getFormMembers(jParams,=
roleNb);
+ Enumeration members =3D grp.members();
+ Principal p =3D null;
+ while (members.hasMoreElements()) {
+ p =3D (Principal) members.nextElement();
+ if (p instanceof JahiaUser) {
+ if (!membersSet.contains((JahiaUser) p=
)) {
+ logger.debug("removed member=3D" +=
p.getName());
+ grp.removeMember((JahiaUser) p);
+ } else {
+ membersSet.remove((JahiaUser) p);
+ }
+ } else if (p instanceof JahiaGroup) {
+ if (!membersSet.contains((JahiaGroup) =
p)) {
+ logger.debug("removed member=3D" +=
p.getName());
+ grp.removeMember((JahiaGroup) p);
+ } else {
+ membersSet.remove((JahiaGroup) p);
+ }
}
}
- }
- Iterator it =3D membersSet.iterator();
- while (it.hasNext()) {
- p =3D (Principal) it.next();
- if (p instanceof JahiaUser) {
- grp.addMember((JahiaUser) p);
- } else if (p instanceof JahiaGroup) {
- grp.addMember((JahiaGroup) p);
+ Iterator it =3D membersSet.iterator();
+ while (it.hasNext()) {
+ p =3D (Principal) it.next();
+ if (p instanceof JahiaUser) {
+ grp.addMember((JahiaUser) p);
+ } else if (p instanceof JahiaGroup) {
+ grp.addMember((JahiaGroup) p);
+ }
}
}
}
}
}
+
Boolean flushApp =3D new Boolean(false);
if (engineMap.get("flushApp") !=3D null) {
flushApp =3D (Boolean) engineMap.get("flushApp");
@@ -399,6 +413,7 @@
=
// list of authorized apps
Vector authAppList =3D new Vector();
+ logger.debug("Application list size before appliing ACL: "+appLis=
t.size());
for (int i =3D 0; i < appList.size(); i++) {
ApplicationBean app =3D (ApplicationBean) appList.get(i);
if (app.getACL().getPermission(null, null, jParams.getUser(), =
JahiaBaseACL.READ_RIGHTS, false, jParams.getSiteID())) {
@@ -417,11 +432,13 @@
int appID =3D -1;
try {
String fieldValue =3D theField.getRawValue();
+ logger.debug("Field value: "+fieldValue);
// fieldValue could contain appID_defName if we come from an
// update, otherwise it simply contains an instanceID.
if ((fieldValue !=3D null) && (fieldValue.indexOf("_") !=3D -1=
)) {
// we found a field value in the form appID_defName
appID =3D ((Integer) engineMap.get(theField.getDefinition(=
).getName() + "_appID")).intValue();
+ logger.debug("Application id: "+appID);
selectedEntryPointDefName =3D (String) engineMap.get(theFi=
eld.getDefinition().getName() + "_selectedEntryPointDefName");
appBean =3D ServicesRegistry.getInstance().getApplications=
ManagerService().getApplication(appID);
} else {
@@ -439,8 +456,11 @@
getApplicationsManagerService().
getEntryPointInstance(
entryPointInstanceID.intValue());
+ // select by default first webapp
if (epInstance =3D=3D null) {
if (authAppList.size() > 0) {
+ // NO DEFAULT VALUES
+ /*logger.debug("By default, select first portlet");
appBean =3D (ApplicationBean) authAppList.get(0);
appID =3D appBean.getID();
ArrayList entryPointDefinitions =3D appBean.getEntryPo=
intDefinitions();
@@ -451,7 +471,7 @@
selectedEntryPointDefName =3D epDef.getName();
} else {
logger.warn("Couldn't retrieve entry point definit=
ions for application " + appBean.getName());
- }
+ } */
}
} else {
selectedEntryPointDefName =3D epInstance.getDefName();
@@ -463,6 +483,7 @@
selectedEntryPointDefName =3D portletDefName;
}
appID =3D epInstance.getApplicationID();
+ logger.debug("application ID from entry point instance: "+=
appID);
appBean =3D ServicesRegistry.getInstance().
getApplicationsManagerService().getApplication(app=
ID);
}
@@ -470,6 +491,14 @@
engineMap.put(theField.getDefinition().getName() + "_selectedE=
ntryPointDefName",
selectedEntryPointDefName);
engineMap.put(theField.getDefinition().getName() + "_appID", n=
ew Integer(appID));
+ logger.debug("Number of allowed application: "+authAppList.siz=
e());
+ if(appBean !=3D null){
+ logger.debug("Selected application ID : "+appBean.getID());
+ logger.debug("Selected application is allowed for current =
user! "+authAppList.contains(appBean));
+ }else{
+ logger.debug("No portlet selected. ");
+ }
+
if (authAppList.size() > 0 && appBean !=3D null && !authAppLis=
t.contains(appBean)) {
engineMap.put(theField.getDefinition().getName() + "_unAut=
horized", Boolean.TRUE);
}
_______________________________________________
cvs_list mailing list
[email protected]
http://lists.jahia.org/cgi-bin/mailman/listinfo/cvs_list