留言板

Permissions Help

H. William Connors II,修改在12 年前。

Permissions Help

New Member 帖子: 24 加入日期: 11-2-3 最近的帖子
I have the following code that I run in an upgrade hook to create an expando column. The creation of the expando column seems to work find as I can see everything in the table however when I try to insert values into the column I get a PrincipalException. I have looked in ExpandoValueServiceImpl.java line 44 and I see the permission check is for ActionKeys.UPDATE. I thought my code that created the expando column should have set that permission for any one with the User role, which my understanding was that any logged in user would get.


System.out.println("Creating expando column: tkdb_id");
    ExpandoColumn tkdbIdColumn = createExpandoColumn(defaultCompanyId,
        Organization.class.getName(), "tkdb_id", ExpandoColumnConstants.LONG);

    System.out.println("Creating expando column: org_type");
    ExpandoColumn orgTypeColumn = createExpandoColumn(defaultCompanyId,
        Organization.class.getName(), "org_type", ExpandoColumnConstants.STRING);


  protected ExpandoColumn createExpandoColumn (long defaultCompanyId,
      String className, String columnName, int columnType)
      throws PortalException, SystemException
  {
    System.out.println("Creating expando column: " + columnName);
    ExpandoTable table = null;
    ExpandoColumn column = null;

    try
    {
      table = ExpandoTableLocalServiceUtil.addTable(defaultCompanyId,
          className, ExpandoTableConstants.DEFAULT_TABLE_NAME);
    }
    catch (DuplicateTableNameException ex)
    {
      table = ExpandoTableLocalServiceUtil.getTable(defaultCompanyId,
          className, ExpandoTableConstants.DEFAULT_TABLE_NAME);
    }

    try
    {
      column = ExpandoColumnLocalServiceUtil.addColumn(table.getTableId(),
          columnName, columnType);
    }
    catch (DuplicateColumnNameException ex)
    {
      column = ExpandoColumnLocalServiceUtil.getColumn(defaultCompanyId,
          className, ExpandoTableConstants.DEFAULT_TABLE_NAME, columnName);
    }

    Role guest = RoleLocalServiceUtil.getRole(defaultCompanyId,
        RoleConstants.GUEST);
    ResourcePermissionLocalServiceUtil.setResourcePermissions(defaultCompanyId,
        ExpandoColumn.class.getName(), ResourceConstants.SCOPE_COMPANY,
        String.valueOf(column.getColumnId()), guest.getRoleId(),
        new String[] { ActionKeys.VIEW });

    Role user = RoleLocalServiceUtil.getRole(defaultCompanyId,
        RoleConstants.USER);
    ResourcePermissionLocalServiceUtil.setResourcePermissions(defaultCompanyId,
        ExpandoColumn.class.getName(), ResourceConstants.SCOPE_COMPANY,
        String.valueOf(column.getColumnId()), user.getRoleId(), new String[] {
            ActionKeys.VIEW, ActionKeys.UPDATE, ActionKeys.DELETE });

    return column;
  }
H. William Connors II,修改在12 年前。

RE: Permissions Help

New Member 帖子: 24 加入日期: 11-2-3 最近的帖子
Ok so my issue had to with trying to use ResourceConstants.SCOPE_COMPANY instead of ResourceConstants.SCOPE_INDIVIDUAL, which leads me to the question can someone explain what those different values mean?