예제 #1
0
  private static LayoutSet _getParentLayoutSet(LayoutSet layoutSet) throws Exception {

    Group group = layoutSet.getGroup();

    if (group.isSite()) {
      Group parentGroup = group.getParentGroup();

      if (parentGroup != null) {
        return LayoutSetLocalServiceUtil.getLayoutSet(
            parentGroup.getGroupId(), layoutSet.isPrivateLayout());
      }
    } else if (group.isUser()) {
      User user = UserLocalServiceUtil.getUser(group.getClassPK());

      List<Organization> organizations =
          OrganizationLocalServiceUtil.getUserOrganizations(user.getUserId());

      if (!organizations.isEmpty()) {
        Organization organization = organizations.get(0);

        Group parentGroup = organization.getGroup();

        return LayoutSetLocalServiceUtil.getLayoutSet(
            parentGroup.getGroupId(), layoutSet.isPrivateLayout());
      }
    }

    return null;
  }
  @Override
  public void checkBaseModel(
      PermissionChecker permissionChecker, long groupId, long primaryKey, String actionId)
      throws PortalException {

    List<Organization> organizations =
        OrganizationLocalServiceUtil.getUserOrganizations(primaryKey);

    long[] organizationsIds = new long[organizations.size()];

    for (int i = 0; i < organizations.size(); i++) {
      Organization organization = organizations.get(i);

      organizationsIds[i] = organization.getOrganizationId();
    }

    check(permissionChecker, primaryKey, organizationsIds, actionId);
  }
  @Override
  public boolean isDisabled(Object obj) {
    Organization organization = (Organization) obj;

    try {
      PasswordPolicyRel passwordPolicyRel =
          PasswordPolicyRelLocalServiceUtil.fetchPasswordPolicyRel(
              Organization.class.getName(), organization.getOrganizationId());

      if ((passwordPolicyRel != null)
          && (passwordPolicyRel.getPasswordPolicyId() != _passwordPolicy.getPasswordPolicyId())) {

        return true;
      }
    } catch (Exception e) {
      _log.error(e, e);
    }

    return false;
  }
  @Override
  public String getOnClick() {
    StringBundler sb = new StringBundler(4);

    try {
      PortletDisplay portletDisplay = themeDisplay.getPortletDisplay();

      sb.append(portletDisplay.getNamespace());

      sb.append("deleteOrganization('");

      Organization organization = ActionUtil.getOrganization(portletRequest);

      sb.append(organization.getOrganizationId());

      sb.append("');");
    } catch (Exception e) {
    }

    return sb.toString();
  }
  @Override
  public boolean contains(
      PermissionChecker permissionChecker, long userId, long[] organizationIds, String actionId) {

    try {
      User user = null;

      if (userId != ResourceConstants.PRIMKEY_DNE) {
        user = UserLocalServiceUtil.getUserById(userId);

        if ((actionId.equals(ActionKeys.DELETE)
                || actionId.equals(ActionKeys.IMPERSONATE)
                || actionId.equals(ActionKeys.PERMISSIONS)
                || actionId.equals(ActionKeys.UPDATE)
                || actionId.equals(ActionKeys.VIEW))
            && !permissionChecker.isOmniadmin()
            && (PortalUtil.isOmniadmin(user)
                || (!permissionChecker.isCompanyAdmin() && PortalUtil.isCompanyAdmin(user)))) {

          return false;
        }

        Contact contact = user.getContact();

        if (permissionChecker.hasOwnerPermission(
                permissionChecker.getCompanyId(),
                User.class.getName(),
                userId,
                contact.getUserId(),
                actionId)
            || (permissionChecker.getUserId() == userId)) {

          return true;
        }
      }

      if (permissionChecker.hasPermission(0, User.class.getName(), userId, actionId)) {

        return true;
      }

      if (user == null) {
        return false;
      }

      if (organizationIds == null) {
        organizationIds = user.getOrganizationIds();
      }

      for (long organizationId : organizationIds) {
        Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

        if (OrganizationPermissionUtil.contains(
            permissionChecker, organization, ActionKeys.MANAGE_USERS)) {

          if (permissionChecker.getUserId() == user.getUserId()) {
            return true;
          }

          Group organizationGroup = organization.getGroup();

          // Organization administrators can only manage normal users.
          // Owners can only manage normal users and administrators.

          if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(
              user.getUserId(),
              organizationGroup.getGroupId(),
              RoleConstants.ORGANIZATION_OWNER,
              true)) {

            continue;
          } else if (UserGroupRoleLocalServiceUtil.hasUserGroupRole(
                  user.getUserId(),
                  organizationGroup.getGroupId(),
                  RoleConstants.ORGANIZATION_ADMINISTRATOR,
                  true)
              && !UserGroupRoleLocalServiceUtil.hasUserGroupRole(
                  permissionChecker.getUserId(),
                  organizationGroup.getGroupId(),
                  RoleConstants.ORGANIZATION_OWNER,
                  true)) {

            continue;
          }

          return true;
        }
      }
    } catch (Exception e) {
      _log.error(e, e);
    }

    return false;
  }