Skip to content

Commit

Permalink
IRoleDAO.retrieveAllRolesWithUserAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed May 14, 2017
1 parent daf530c commit 9b31974
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public interface IRoleDAO extends ISingletonService
*/
List<I_AD_Role> retrieveAllRolesWithAutoMaintenance(Properties ctx);

/**
* @return all roles on which current user has access
*/
List<I_AD_Role> retrieveAllRolesWithUserAccess(Properties ctx);

/**
* @param ctx
* @param adClientId AD_Client_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,30 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/


import java.util.Date;
import java.util.List;
import java.util.Properties;

import org.adempiere.ad.dao.IQueryBL;
import org.adempiere.ad.security.IRoleDAO;
import org.adempiere.ad.security.IRolesTreeNode;
import org.adempiere.ad.security.IUserRolePermissions;
import org.adempiere.ad.trx.api.ITrx;
import org.adempiere.model.InterfaceWrapperHelper;
import org.adempiere.util.Services;
import org.adempiere.util.proxy.Cached;
import org.compiere.model.I_AD_Role_Included;
import org.compiere.model.I_AD_User_Roles;
import org.compiere.model.I_AD_User_Substitute;
import org.compiere.model.MRole;
import org.compiere.util.Env;

import com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -65,12 +64,14 @@ public I_AD_Role retrieveRole(@CacheCtx final Properties ctx, final int AD_Role_
return null;
}
// special Handling for System Role because of ID=ZERO
else if (AD_Role_ID == 0)
else if (AD_Role_ID == IUserRolePermissions.SYSTEM_ROLE_ID)
{
// FIXME: check if it's really needed
final MRole role = new MRole(ctx, AD_Role_ID, ITrx.TRXNAME_None);
role.load(ITrx.TRXNAME_None);
return InterfaceWrapperHelper.create(role, I_AD_Role.class);
// TODO: check retrieving from cache first
return Services.get(IQueryBL.class)
.createQueryBuilder(I_AD_Role.class, ctx, ITrx.TRXNAME_None)
.addEqualsFilter(I_AD_Role.COLUMNNAME_AD_Role_ID, IUserRolePermissions.SYSTEM_ROLE_ID)
.create()
.firstOnlyNotNull(I_AD_Role.class);
}
else
// if (AD_Role_ID > 0)
Expand Down Expand Up @@ -164,6 +165,18 @@ public List<I_AD_Role> retrieveAllRolesWithAutoMaintenance(final Properties ctx)
.list();
}

@Override
public List<I_AD_Role> retrieveAllRolesWithUserAccess(final Properties ctx)
{
return Services.get(IQueryBL.class)
.createQueryBuilder(I_AD_Role.class, ctx, ITrx.TRXNAME_None)
.addEqualsFilter(I_AD_Role.COLUMNNAME_IsManual, false)
.addOnlyActiveRecordsFilter()
.create()
.setApplyAccessFilterRW(IUserRolePermissions.SQL_RO)
.list(I_AD_Role.class);
}

@Override
public List<I_AD_Role> retrieveRolesForClient(final Properties ctx, final int adClientId)
{
Expand All @@ -181,8 +194,8 @@ public String retrieveRoleName(final Properties ctx, final int adRoleId)
final I_AD_Role role = retrieveRole(ctx, adRoleId);
return role == null ? "<" + adRoleId + ">" : role.getName();
}
@Override

@Override
public boolean hasUserRoleAssignment(final Properties ctx, final int adUserId, final int adRoleId)
{
return Services.get(IQueryBL.class)
Expand Down

0 comments on commit 9b31974

Please sign in to comment.