Search in sources :

Example 21 with MRole

use of org.compiere.model.MRole in project lar_361 by comitsrl.

the class Info method testCount.

// executeQuery
/**
 * 	Test Row Count
 *	@return true if display
 */
private boolean testCount() {
    long start = System.currentTimeMillis();
    String dynWhere = getSQLWhere();
    StringBuffer sql = new StringBuffer(m_sqlCount);
    if (dynWhere.length() > 0)
        // includes first AND
        sql.append(dynWhere);
    // Variables
    String countSql = Msg.parseTranslation(Env.getCtx(), sql.toString());
    countSql = MRole.getDefault().addAccessSQL(countSql, getTableName(), MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO);
    log.finer(countSql);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    int no = -1;
    try {
        pstmt = DB.prepareStatement(countSql, null);
        setParameters(pstmt, true);
        rs = pstmt.executeQuery();
        if (rs.next())
            no = rs.getInt(1);
    } catch (Exception e) {
        log.log(Level.SEVERE, countSql, e);
        no = -2;
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    log.fine("#" + no + " - " + (System.currentTimeMillis() - start) + "ms");
    // Armen: add role checking (Patch #1694788 )
    MRole role = MRole.getDefault();
    if (role.isQueryMax(no))
        return ADialog.ask(p_WindowNo, this, "InfoHighRecordCount", String.valueOf(no));
    return true;
}
Also used : MRole(org.compiere.model.MRole) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 22 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class AProcessModel method fetchProcesses.

public List<I_AD_Process> fetchProcesses(Properties ctx, GridTab gridTab) {
    final List<I_AD_Process> emptyList = Collections.unmodifiableList(new ArrayList<I_AD_Process>());
    if (gridTab == null) {
        return emptyList;
    }
    final MRole role = MRole.getDefault(ctx, false);
    Check.assumeNotNull(role, "No role found for {0}", ctx);
    final int AD_Table_ID = gridTab.getAD_Table_ID();
    final List<I_AD_Process> list = fetchProcessesForTable(ctx, AD_Table_ID);
    for (Iterator<I_AD_Process> it = list.iterator(); it.hasNext(); ) {
        final I_AD_Process process = it.next();
        // Filter out processes on which we don't have access
        final Boolean accessRW = role.checkProcessAccess(process.getAD_Process_ID());
        if (accessRW == null) {
            logger.log(Level.FINE, "Removing process {0} because user has no access at all to it", process);
            it.remove();
            continue;
        } else if (!accessRW) {
            logger.log(Level.FINE, "Removing process {0} because user has only readonly access to it", process);
            it.remove();
            continue;
        }
        // Filter out processes which have preconditions which don't apply
        if (!isPreconditionApplicable(process, gridTab)) {
            logger.log(Level.FINE, "Removing process {0} because preconditions were not met", process);
            it.remove();
            continue;
        }
    }
    return list;
}
Also used : I_AD_Process(org.compiere.model.I_AD_Process) MRole(org.compiere.model.MRole)

Example 23 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class Archive method cmd_query.

//	isSame
/**************************************************************************
	 * 	Create Query
	 */
public void cmd_query(boolean reports, KeyNamePair process, KeyNamePair table, Integer C_BPartner_ID, String name, String description, String help, KeyNamePair createdBy, Timestamp createdFrom, Timestamp createdTo) {
    StringBuffer sql = new StringBuffer();
    MRole role = MRole.getDefault();
    if (!role.isCanReport()) {
        log.warning("User/Role cannot Report AD_User_ID=" + Env.getAD_User_ID(Env.getCtx()));
        return;
    }
    sql.append(" AND IsReport=").append(reports ? "'Y'" : "'N'");
    //	Process
    if (reports) {
        if (process != null && process.getKey() > 0)
            sql.append(" AND AD_Process_ID=").append(process.getKey());
    }
    //	Table
    if (m_AD_Table_ID > 0) {
        sql.append(" AND ((AD_Table_ID=").append(m_AD_Table_ID);
        if (m_Record_ID > 0)
            sql.append(" AND Record_ID=").append(m_Record_ID);
        sql.append(")");
        if (m_AD_Table_ID == MBPartner.Table_ID && m_Record_ID > 0)
            sql.append(" OR C_BPartner_ID=").append(m_Record_ID);
        sql.append(")");
        //	Reset for query
        m_AD_Table_ID = 0;
        m_Record_ID = 0;
    } else {
        if (table != null && table.getKey() > 0)
            sql.append(" AND AD_Table_ID=").append(table.getKey());
    }
    //	Business Partner
    if (!reports) {
        if (C_BPartner_ID != null)
            sql.append(" AND C_BPartner_ID=").append(C_BPartner_ID);
        else
            sql.append(" AND C_BPartner_ID IS NOT NULL");
    }
    //	Name
    if (name != null && name.length() > 0) {
        if (name.indexOf('%') != -1 || name.indexOf('_') != -1)
            sql.append(" AND Name LIKE ").append(DB.TO_STRING(name));
        else
            sql.append(" AND Name=").append(DB.TO_STRING(name));
    }
    //	Description
    if (description != null && description.length() > 0) {
        if (description.indexOf('%') != -1 || description.indexOf('_') != -1)
            sql.append(" AND Description LIKE ").append(DB.TO_STRING(description));
        else
            sql.append(" AND Description=").append(DB.TO_STRING(description));
    }
    //	Help
    if (help != null && help.length() > 0) {
        if (help.indexOf('%') != -1 || help.indexOf('_') != -1)
            sql.append(" AND Help LIKE ").append(DB.TO_STRING(help));
        else
            sql.append(" AND Help=").append(DB.TO_STRING(help));
    }
    //	CreatedBy
    if (createdBy != null && createdBy.getKey() > 0)
        sql.append(" AND CreatedBy=").append(createdBy.getKey());
    //	Created
    if (createdFrom != null)
        sql.append(" AND Created>=").append(DB.TO_DATE(createdFrom, true));
    if (createdTo != null)
        sql.append(" AND Created<").append(DB.TO_DATE(TimeUtil.addDays(createdTo, 1), true));
    log.fine(sql.toString());
    //metas: Bugfix zu included_Role
    //	Process Access
    sql.append(" AND (AD_Process_ID IS NULL OR AD_Process_ID IN " + "(SELECT AD_Process_ID FROM AD_Process_Access WHERE AD_Role_ID=").append(role.getAD_Role_ID()).append(" OR ").append(role.getIncludedRolesWhereClause("AD_Role_ID", null)).append("))");
    //	Table Access
    sql.append(" AND (AD_Table_ID IS NULL " + //	Menu Reports 
    "OR (AD_Table_ID IS NOT NULL AND AD_Process_ID IS NOT NULL) " + "OR AD_Table_ID IN " + "(SELECT t.AD_Table_ID FROM AD_Tab t" + " INNER JOIN AD_Window_Access wa ON (t.AD_Window_ID=wa.AD_Window_ID) " + "WHERE wa.AD_Role_ID=").append(role.getAD_Role_ID()).append(" OR ").append(role.getIncludedRolesWhereClause("wa.AD_Role_ID", null)).append("))");
    log.finest(sql.toString());
    //metas: Bugfix zu included_Role ende
    //
    m_archives = MArchive.get(Env.getCtx(), sql.toString());
    log.info("Length=" + m_archives.length);
}
Also used : MRole(org.compiere.model.MRole)

Example 24 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class Archive method getProcessData.

public KeyNamePair[] getProcessData() {
    // Processes
    // metas
    final MRole role = MRole.getDefault();
    //		int AD_Role_ID = Env.getAD_Role_ID(Env.getCtx());
    boolean trl = !Env.isBaseLanguage(Env.getCtx(), "AD_Process");
    String lang = Env.getAD_Language(Env.getCtx());
    // TODO: ASP - implement process and window access ASP control
    String sql = "SELECT DISTINCT p.AD_Process_ID," + (trl ? "trl.Name" : "p.Name ") + " FROM AD_Process p INNER JOIN AD_Process_Access pa ON (p.AD_Process_ID=pa.AD_Process_ID) " + (trl ? "LEFT JOIN AD_Process_Trl trl on (trl.AD_Process_ID=p.AD_Process_ID and trl.AD_Language=" + DB.TO_STRING(lang) + ")" : "") + " WHERE " + // metas: use included roles
    role.getIncludedRolesWhereClause("pa.AD_Role_ID", null) + " AND p.IsReport='Y' AND p.IsActive='Y' AND pa.IsActive='Y' " + "ORDER BY 2";
    return DB.getKeyNamePairs(sql, true);
}
Also used : MRole(org.compiere.model.MRole)

Example 25 with MRole

use of org.compiere.model.MRole in project adempiere by adempiere.

the class MyValidator method beforeSaveProperties.

//	toString
/**
	 * Sample Validator Before Save Properties - to set mandatory properties on users
	 * avoid users changing properties
	 */
public void beforeSaveProperties() {
    // not for SuperUser or role SysAdmin
    if (// System
    m_AD_User_ID == 0 || // SuperUser
    m_AD_User_ID == 100 || // System Administrator
    m_AD_Role_ID == 0 || // ECO Admin
    m_AD_Role_ID == 1000000)
        return;
    log.info("Setting default Properties");
    MRole role = MRole.get(Env.getCtx(), m_AD_Role_ID);
// Example - if you don't want user to select auto commit property
// Ini.setProperty(Ini.P_A_COMMIT, false);
// Example - if you don't want user to select auto login
// Ini.setProperty(Ini.P_A_LOGIN, false);
// Example - if you don't want user to select store password
// Ini.setProperty(Ini.P_STORE_PWD, false);
// Example - if you want your user inherit ALWAYS the show accounting from role
// Ini.setProperty(Ini.P_SHOW_ACCT, role.isShowAcct());
// Example - if you want to avoid your user from changing the working date
/*
		Timestamp DEFAULT_TODAY =	new Timestamp(System.currentTimeMillis());
		//  Date (remove seconds)
		DEFAULT_TODAY.setHours(0);
		DEFAULT_TODAY.setMinutes(0);
		DEFAULT_TODAY.setSeconds(0);
		DEFAULT_TODAY.setNanos(0);
		Ini.setProperty(Ini.P_TODAY, DEFAULT_TODAY.toString());
		Env.setContext(Env.getCtx(), "#Date", DEFAULT_TODAY);
		*/
}
Also used : MRole(org.compiere.model.MRole)

Aggregations

MRole (org.compiere.model.MRole)42 PreparedStatement (java.sql.PreparedStatement)14 ResultSet (java.sql.ResultSet)14 SQLException (java.sql.SQLException)11 ArrayList (java.util.ArrayList)7 Point (java.awt.Point)4 Properties (java.util.Properties)4 BigDecimal (java.math.BigDecimal)3 Statement (java.sql.Statement)3 GridField (org.compiere.model.GridField)3 GridTab (org.compiere.model.GridTab)3 QName (javax.xml.namespace.QName)2 MBrowse (org.adempiere.model.MBrowse)2 XFireFault (org.codehaus.xfire.fault.XFireFault)2 ICreateFrom (org.compiere.grid.ICreateFrom)2 MOrgInfo (org.compiere.model.MOrgInfo)2 MProcess (org.compiere.model.MProcess)2 MTable (org.compiere.model.MTable)2 MWFActivity (org.compiere.wf.MWFActivity)2 ADLoginRequest (pl.x3E.adInterface.ADLoginRequest)2