1 31 32 package org.opencms.workplace.tools.accounts; 33 34 import org.opencms.file.CmsGroup; 35 import org.opencms.file.CmsResource; 36 import org.opencms.file.CmsUser; 37 import org.opencms.i18n.CmsMessageContainer; 38 import org.opencms.jsp.CmsJspActionElement; 39 import org.opencms.main.CmsException; 40 import org.opencms.main.CmsRuntimeException; 41 import org.opencms.security.CmsAccessControlEntry; 42 import org.opencms.util.CmsIdentifiableObjectContainer; 43 import org.opencms.util.CmsStringUtil; 44 import org.opencms.util.CmsUUID; 45 import org.opencms.workplace.CmsDialog; 46 import org.opencms.workplace.CmsWorkplaceSettings; 47 import org.opencms.workplace.list.A_CmsListDialog; 48 import org.opencms.workplace.list.CmsHtmlList; 49 import org.opencms.workplace.list.CmsListColumnAlignEnum; 50 import org.opencms.workplace.list.CmsListColumnDefinition; 51 import org.opencms.workplace.list.CmsListDirectAction; 52 import org.opencms.workplace.list.CmsListItem; 53 import org.opencms.workplace.list.CmsListItemActionIconComparator; 54 import org.opencms.workplace.list.CmsListMetadata; 55 import org.opencms.workplace.list.CmsListOrderEnum; 56 57 import java.io.IOException ; 58 import java.util.HashMap ; 59 import java.util.Iterator ; 60 import java.util.List ; 61 import java.util.Map ; 62 63 import javax.servlet.ServletException ; 64 import javax.servlet.http.HttpServletRequest ; 65 import javax.servlet.http.HttpServletResponse ; 66 import javax.servlet.jsp.JspException ; 67 import javax.servlet.jsp.PageContext ; 68 69 78 public class CmsGroupDependenciesList extends A_CmsListDialog { 79 80 81 public static final int ACTION_DELETE = 131; 82 83 84 public static final int ACTION_TRANSFER = 132; 85 86 87 public static final String DELETE_ACTION = "delete"; 88 89 90 public static final String LIST_ACTION_ICON = "ai"; 91 92 93 public static final String LIST_COLUMN_ICON = "ci"; 94 95 96 public static final String LIST_COLUMN_NAME = "cn"; 97 98 99 public static final String LIST_COLUMN_TYPE = "ct"; 100 101 102 public static final String LIST_COLUMN_PERMISSIONS = "cp"; 103 104 105 public static final String LIST_ID = "lgd"; 106 107 108 public static final String PARAM_GROUPID = "groupid"; 109 110 111 public static final String PATH_BUTTONS = "tools/accounts/buttons/"; 112 113 114 public static final String TRANSFER_ACTION = "transfer"; 115 116 117 private String m_groupName; 118 119 120 private String m_paramGroupid; 121 122 127 public CmsGroupDependenciesList(CmsJspActionElement jsp) { 128 129 this(LIST_ID, jsp); 130 } 131 132 139 public CmsGroupDependenciesList(PageContext context, HttpServletRequest req, HttpServletResponse res) { 140 141 this(new CmsJspActionElement(context, req, res)); 142 } 143 144 150 protected CmsGroupDependenciesList(String listId, CmsJspActionElement jsp) { 151 152 super( 153 jsp, 154 listId, 155 Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_LIST_NAME_0), 156 LIST_COLUMN_NAME, 157 CmsListOrderEnum.ORDER_ASCENDING, 158 LIST_COLUMN_NAME); 159 } 160 161 164 public void actionDialog() throws JspException , ServletException , IOException { 165 166 switch (getAction()) { 167 case ACTION_DELETE: 168 Iterator it = CmsStringUtil.splitAsList(getGroupName(), CmsHtmlList.ITEM_SEPARATOR, true).iterator(); 169 while (it.hasNext()) { 170 String name = (String )it.next(); 171 try { 172 getCms().deleteGroup(name); 173 } catch (CmsException e) { 174 throw new CmsRuntimeException(e.getMessageContainer(), e); 175 } 176 } 177 setAction(ACTION_CANCEL); 178 actionCloseDialog(); 179 break; 180 case ACTION_TRANSFER: 181 Map params = new HashMap (); 182 params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL); 184 params.put(PARAM_GROUPID, getParamGroupid()); 186 getToolManager().jspForwardPage( 187 this, 188 getJsp().getRequestContext().getFolderUri() + "group_transfer.jsp", 189 params); 190 break; 191 192 default: 193 super.actionDialog(); 194 } 195 } 196 197 200 public String defaultActionHtmlContent() { 201 202 if (getList().getTotalSize() > 0) { 203 return super.defaultActionHtmlContent(); 204 } 205 return ""; 206 } 207 208 211 public void executeListMultiActions() { 212 213 throwListUnsupportedActionException(); 214 } 215 216 219 public void executeListSingleActions() { 220 221 throwListUnsupportedActionException(); 222 } 223 224 229 public String getGroupName() { 230 231 return m_groupName; 232 } 233 234 239 public String getParamGroupid() { 240 241 return m_paramGroupid; 242 } 243 244 249 public void setParamGroupid(String groupId) { 250 251 m_paramGroupid = groupId; 252 } 253 254 257 protected String customHtmlEnd() { 258 259 StringBuffer result = new StringBuffer (512); 260 result.append(super.customHtmlEnd()); 261 result.append("<form name='actions' method='post' action='"); 262 result.append(getDialogRealUri()); 263 result.append("' class='nomargin' onsubmit=\"return submitAction('ok', null, 'actions');\">\n"); 264 result.append(allParamsAsHidden()); 265 result.append(dialogButtonRow(HTML_START)); 266 result.append("<input name='"); 267 result.append(DELETE_ACTION); 268 result.append("' type='button' value='"); 269 result.append(Messages.get().container(Messages.GUI_DEPENDENCIES_BUTTON_DELETE_0).key(getLocale())); 270 result.append("' onclick=\"submitAction('"); 271 result.append(DELETE_ACTION); 272 result.append("', form);\" class='dialogbutton'>\n"); 273 if (getList().getTotalSize() > 0) { 274 result.append("<input name='"); 275 result.append(TRANSFER_ACTION); 276 result.append("' type='button' value='"); 277 result.append(Messages.get().container(Messages.GUI_DEPENDENCIES_BUTTON_TRANSFER_0).key(getLocale())); 278 result.append("' onclick=\"submitAction('"); 279 result.append(TRANSFER_ACTION); 280 result.append("', form);\" class='dialogbutton'>\n"); 281 } 282 dialogButtonsHtml(result, BUTTON_CANCEL, ""); 283 result.append(dialogButtonRow(HTML_END)); 284 result.append("</form>\n"); 285 return result.toString(); 286 } 287 288 291 protected String customHtmlStart() { 292 293 StringBuffer result = new StringBuffer (512); 294 result.append(dialogBlockStart(Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_NOTICE_0).key( 295 getLocale()))); 296 if (getCurrentToolPath().indexOf("/edit/") < 0) { 297 result.append(key(Messages.GUI_GROUP_DEPENDENCIES_SELECTED_GROUPS_0)); 298 result.append(":<br>\n"); 299 List users = CmsStringUtil.splitAsList(getGroupName(), CmsHtmlList.ITEM_SEPARATOR, true); 300 result.append("<ul>\n"); 301 Iterator it = users.iterator(); 302 while (it.hasNext()) { 303 String name = (String )it.next(); 304 result.append("<li>"); 305 result.append(name); 306 result.append("</li>\n"); 307 } 308 result.append("</ul>\n"); 309 } 310 if (getList().getTotalSize() > 0) { 311 result.append(key(Messages.GUI_GROUP_DEPENDENCIES_NOTICE_TEXT_0)); 312 } else { 313 result.append(key(Messages.GUI_GROUP_DEPENDENCIES_DELETE_0)); 314 } 315 result.append(dialogBlockEnd()); 316 return result.toString(); 317 } 318 319 322 protected void fillDetails(String detailId) { 323 324 } 326 327 330 protected List getListItems() throws CmsException { 331 332 CmsIdentifiableObjectContainer ret = new CmsIdentifiableObjectContainer(true, false); 333 Iterator itGroups = CmsStringUtil.splitAsList(getParamGroupid(), CmsHtmlList.ITEM_SEPARATOR, true).iterator(); 334 getCms().getRequestContext().saveSiteRoot(); 335 getCms().getRequestContext().setSiteRoot("/"); 336 while (itGroups.hasNext()) { 337 CmsGroup group = getCms().readGroup(new CmsUUID(itGroups.next().toString())); 338 List resources = getCms().getResourcesForPrincipal(group.getId(), null, true); 340 Iterator itRes = resources.iterator(); 341 while (itRes.hasNext()) { 342 CmsResource resource = (CmsResource)itRes.next(); 343 CmsListItem item = (CmsListItem)ret.getObject(resource.getResourceId().toString()); 344 if (item == null) { 345 item = getList().newItem(resource.getResourceId().toString()); 346 item.set(LIST_COLUMN_NAME, resource.getRootPath()); 347 item.set(LIST_COLUMN_TYPE, new Integer (resource.getTypeId())); 348 Iterator itAces = getCms().getAccessControlEntries(resource.getRootPath(), false).iterator(); 349 while (itAces.hasNext()) { 350 CmsAccessControlEntry ace = (CmsAccessControlEntry)itAces.next(); 351 if (ace.getPrincipal().equals(group.getId())) { 352 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(ace.getPermissions().getPermissionString())) { 353 item.set(LIST_COLUMN_PERMISSIONS, group.getName() 354 + ": " 355 + ace.getPermissions().getPermissionString()); 356 } 357 break; 358 } 359 } 360 ret.addIdentifiableObject(item.getId(), item); 361 } else { 362 String oldData = (String )item.get(LIST_COLUMN_PERMISSIONS); 363 Iterator itAces = getCms().getAccessControlEntries(resource.getRootPath(), false).iterator(); 364 while (itAces.hasNext()) { 365 CmsAccessControlEntry ace = (CmsAccessControlEntry)itAces.next(); 366 if (ace.getPrincipal().equals(group.getId())) { 367 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(ace.getPermissions().getPermissionString())) { 368 String data = group.getName() + ": " + ace.getPermissions().getPermissionString(); 369 if (oldData != null) { 370 data = oldData + ", " + data; 371 } 372 item.set(LIST_COLUMN_PERMISSIONS, data); 373 } 374 break; 375 } 376 } 377 } 378 } 379 Iterator itUsers = getCms().getUsersOfGroup(group.getName()).iterator(); 381 while (itUsers.hasNext()) { 382 CmsUser user = (CmsUser)itUsers.next(); 383 CmsListItem item = (CmsListItem)ret.getObject(user.getId().toString()); 384 if (item == null) { 385 item = getList().newItem(user.getId().toString()); 386 item.set(LIST_COLUMN_NAME, user.getName()); 387 item.set(LIST_COLUMN_PERMISSIONS, "--"); 388 ret.addIdentifiableObject(item.getId(), item); 389 } 390 } 391 Iterator itChilds = getCms().getChild(group.getName()).iterator(); 393 while (itChilds.hasNext()) { 394 CmsGroup child = (CmsGroup)itChilds.next(); 395 CmsListItem item = (CmsListItem)ret.getObject(child.getId().toString()); 396 if (item == null) { 397 item = getList().newItem(child.getId().toString()); 398 item.set(LIST_COLUMN_NAME, child.getName()); 399 item.set(LIST_COLUMN_PERMISSIONS, "--"); 400 ret.addIdentifiableObject(item.getId(), item); 401 } 402 } 403 } 404 getCms().getRequestContext().restoreSiteRoot(); 405 return ret.elementList(); 406 } 407 408 411 protected void initMessages() { 412 413 addMessages(Messages.get().getBundleName()); 415 addMessages(org.opencms.workplace.Messages.get().getBundleName()); 417 super.initMessages(); 419 } 420 421 424 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 425 426 super.initWorkplaceRequestValues(settings, request); 427 if (DELETE_ACTION.equals(getParamAction())) { 428 setAction(ACTION_DELETE); 429 } else if (TRANSFER_ACTION.equals(getParamAction())) { 430 setAction(ACTION_TRANSFER); 431 } 432 } 433 434 437 protected void setColumns(CmsListMetadata metadata) { 438 439 CmsListColumnDefinition iconCol = new CmsListColumnDefinition(LIST_COLUMN_ICON); 441 iconCol.setName(Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_LIST_COLS_ICON_0)); 442 iconCol.setHelpText(Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_LIST_COLS_ICON_HELP_0)); 443 iconCol.setWidth("20"); 444 iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 445 iconCol.setListItemComparator(new CmsListItemActionIconComparator()); 446 447 setIconActions(iconCol); 449 450 metadata.addColumn(iconCol); 452 453 CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_NAME); 455 nameCol.setName(Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_LIST_COLS_NAME_0)); 456 nameCol.setWidth("80%"); 457 metadata.addColumn(nameCol); 458 459 CmsListColumnDefinition permissionsCol = new CmsListColumnDefinition(LIST_COLUMN_PERMISSIONS); 461 permissionsCol.setName(Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_LIST_COLS_PERMISSIONS_0)); 462 permissionsCol.setWidth("20%"); 463 metadata.addColumn(permissionsCol); 464 465 CmsListColumnDefinition typeCol = new CmsListColumnDefinition(LIST_COLUMN_TYPE); 467 typeCol.setName(new CmsMessageContainer(null, "type")); 468 typeCol.setVisible(false); 469 metadata.addColumn(typeCol); 470 } 471 472 477 protected void setIconActions(CmsListColumnDefinition iconCol) { 478 479 CmsListDirectAction resourceIconAction = new CmsDependencyIconAction( 481 LIST_ACTION_ICON, 482 CmsDependencyIconActionType.RESOURCE, 483 getCms()); 484 resourceIconAction.setName(Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_RES_NAME_0)); 485 resourceIconAction.setHelpText(Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_RES_HELP_0)); 486 resourceIconAction.setEnabled(false); 487 iconCol.addDirectAction(resourceIconAction); 488 489 CmsListDirectAction groupIconAction = new CmsDependencyIconAction( 491 LIST_ACTION_ICON, 492 CmsDependencyIconActionType.GROUP, 493 getCms()); 494 groupIconAction.setName(Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_GRP_NAME_0)); 495 groupIconAction.setHelpText(Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_GRP_HELP_0)); 496 groupIconAction.setEnabled(false); 497 iconCol.addDirectAction(groupIconAction); 498 499 CmsListDirectAction userIconAction = new CmsDependencyIconAction( 501 LIST_ACTION_ICON, 502 CmsDependencyIconActionType.USER, 503 getCms()); 504 userIconAction.setName(Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_USR_NAME_0)); 505 userIconAction.setHelpText(Messages.get().container(Messages.GUI_GROUP_DEPENDENCIES_LIST_ACTION_USR_HELP_0)); 506 userIconAction.setEnabled(false); 507 iconCol.addDirectAction(userIconAction); 508 } 509 510 513 protected void setIndependentActions(CmsListMetadata metadata) { 514 515 } 517 518 521 protected void setMultiActions(CmsListMetadata metadata) { 522 523 } 525 526 529 protected void validateParamaters() throws Exception { 530 531 m_groupName = ""; 533 Iterator itGroups = CmsStringUtil.splitAsList(getParamGroupid(), CmsHtmlList.ITEM_SEPARATOR, true).iterator(); 534 while (itGroups.hasNext()) { 535 CmsUUID id = new CmsUUID(itGroups.next().toString()); 536 m_groupName += getCms().readGroup(id).getName(); 537 if (itGroups.hasNext()) { 538 m_groupName += CmsHtmlList.ITEM_SEPARATOR; 539 } 540 } 541 } 542 } | Popular Tags |