/// <summary> /// Is Role Responsible /// </summary> /// <returns>true if role</returns> public MRole GetRole() { if (!IsRole()) { return(null); } return(MRole.Get(GetCtx(), GetAD_Role_ID())); }
/// <summary> /// Set AD_Process_ID. /// Check Role if process can be performed /// </summary> /// <param name="AD_Process_ID">process</param> public void SetAD_Process_ID(int AD_CrytalProcess_ID) { if (AD_CrytalProcess_ID <= 0) { return; } Console.WriteLine(AD_CrytalProcess_ID.ToString()); int AD_Role_ID = Utility.Env.GetContext().GetAD_Role_ID(); if (AD_Role_ID != 0) { MRole role = MRole.Get(GetCtx(), AD_Role_ID); //bool? access = role.GetProcessAccess(AD_CrytalProcess_ID); //if (access == null) // throw new Exception("Cannot access Process " + AD_CrytalProcess_ID // + " with Role: " + role.Get_Value("Name")); } base.SetAD_CrystalInstance_ID(AD_CrytalProcess_ID); }
/// <summary> /// Set AD_Process_ID. /// Check Role if process can be performed /// </summary> /// <param name="AD_Process_ID">process</param> public new void SetAD_Process_ID(int AD_Process_ID) { if (AD_Process_ID <= 0) { return; } Console.WriteLine(AD_Process_ID.ToString()); int AD_Role_ID = GetCtx().GetAD_Role_ID(); if (AD_Role_ID != 0) { MRole role = MRole.Get(GetCtx(), AD_Role_ID); bool? access = role.GetProcessAccess(AD_Process_ID, AD_Role_ID); if (access == null) { throw new Exception("Cannot access Process " + AD_Process_ID + " with Role: " + role.Get_Value("Name")); } } base.SetAD_Process_ID(AD_Process_ID); }
/// <summary> /// Complete the Payment Record /// </summary> /// <param name="ctx">Context</param> /// <param name="Record_ID">C_Payment_ID</param> /// <param name="Process_ID">AD_Process_ID</param> /// <param name="DocAction">Documnet Action</param> /// <returns>return message</returns> public string CompletePayment(Ctx ctx, int Record_ID, int Process_ID, string DocAction) { string result = ""; MRole role = MRole.Get(ctx, ctx.GetAD_Role_ID()); if (Util.GetValueOfBool(role.GetProcessAccess(Process_ID))) { DB.ExecuteQuery("UPDATE C_Payment SET DocAction = '" + DocAction + "' WHERE C_Payment_ID = " + Record_ID); MProcess proc = new MProcess(ctx, Process_ID, null); MPInstance pin = new MPInstance(proc, Record_ID); if (!pin.Save()) { ValueNamePair vnp = VLogger.RetrieveError(); string errorMsg = ""; if (vnp != null) { errorMsg = vnp.GetName(); if (errorMsg == "") { errorMsg = vnp.GetValue(); } } if (errorMsg == "") { result = Msg.GetMsg(ctx, "DocNotCompleted"); } return(result); } MPInstancePara para = new MPInstancePara(pin, 20); para.setParameter("DocAction", DocAction); if (!para.Save()) { //String msg = "No DocAction Parameter added"; // not translated } ProcessInfo pi = new ProcessInfo("WF", Process_ID); pi.SetAD_User_ID(ctx.GetAD_User_ID()); pi.SetAD_Client_ID(ctx.GetAD_Client_ID()); pi.SetAD_PInstance_ID(pin.GetAD_PInstance_ID()); pi.SetRecord_ID(Record_ID); pi.SetTable_ID(335); //AD_Table_ID=335 for C_Payment ProcessCtl worker = new ProcessCtl(ctx, null, pi, null); worker.Run(); if (pi.IsError()) { ValueNamePair vnp = VLogger.RetrieveError(); string errorMsg = ""; if (vnp != null) { errorMsg = vnp.GetName(); if (errorMsg == "") { errorMsg = vnp.GetValue(); } } if (errorMsg == "") { errorMsg = pi.GetSummary(); } if (errorMsg == "") { errorMsg = Msg.GetMsg(ctx, "DocNotCompleted"); } result = errorMsg; return(result); } else { result = ""; } } else { result = Msg.GetMsg(ctx, "NoAccess"); return(result); } return(result); }
/// <summary> /// return org access list aginst client and role of user /// </summary> /// <param name="AD_Role_ID">role id </param> /// <param name="AD_User_ID">user id</param> /// <param name="AD_Client_ID"> client id</param> /// <returns></returns> public static List <KeyNamePair> GetOrgs(int AD_Role_ID, int AD_User_ID, int AD_Client_ID) { List <KeyNamePair> list = new List <KeyNamePair>(); String sql = "SELECT o.AD_Org_ID,o.Name,o.IsSummary " // 1..3 + "FROM AD_Role r, AD_Client c" + " INNER JOIN AD_Org o ON (c.AD_Client_ID=o.AD_Client_ID OR o.AD_Org_ID=0) " + "WHERE r.AD_Role_ID='" + AD_Role_ID + "'" // #1 + " AND c.AD_Client_ID='" + AD_Client_ID + "'" // #2 + " AND o.IsActive='Y' AND o.IsSummary='N' AND o.IsCostCenter='N' AND o.IsProfitCenter='N' " + " AND (r.IsAccessAllOrgs='Y' " + "OR (r.IsUseUserOrgAccess='N' AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_Role_OrgAccess ra " + "WHERE ra.AD_Role_ID=r.AD_Role_ID AND ra.IsActive='Y')) " + "OR (r.IsUseUserOrgAccess='Y' AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_User_OrgAccess ua " + "WHERE ua.AD_User_ID='" + AD_User_ID + "' AND ua.IsActive='Y'))" // #3 + ") " + "ORDER BY o.Name"; // MRole role = null; IDataReader dr = null; //list.Add(new KeyNamePair(-1, "Select")); try { dr = DB.ExecuteReader(sql); // load Orgs Ctx ctx = new Ctx(); while (dr.Read()) { int AD_Org_ID = Util.GetValueOfInt(dr[0].ToString()); String Name = dr[1].ToString(); bool summary = "Y".Equals(dr[2].ToString()); if (summary) { if (role == null) { ctx.SetAD_Client_ID(AD_Client_ID); role = MRole.Get(ctx, AD_Role_ID, AD_User_ID, false); } GetOrgsAddSummary(list, AD_Org_ID, Name, role, ctx); } else { KeyNamePair p = new KeyNamePair(AD_Org_ID, Name); if (!list.Contains(p)) { list.Add(p); } } } dr.Close(); // //retValue = new KeyNamePair[list.Count]; // retValue = list.ToArray(); } catch { if (dr != null) { dr.Close(); } } // No Orgs return(list); } // getOrgs
/// <summary> /// /// </summary> /// <param name="client"></param> /// <returns></returns> public KeyNamePair[] GetOrgs(KeyNamePair client) { if (client == null) { throw new ArgumentException("Client missing"); } // Web Store Login if (m_store != null) { return new KeyNamePair[] { new KeyNamePair(m_store.GetAD_Org_ID(), m_store.GetName() + " Org") } } ; if (m_ctx.GetContext("#AD_Role_ID").Length == 0) // could be number 0 { throw new Exception("Missing Context #AD_Role_ID"); } int AD_Role_ID = m_ctx.GetAD_Role_ID(); int AD_User_ID = m_ctx.GetAD_User_ID(); // s_log.fine("Client: " + client.toStringX() + ", AD_Role_ID=" + AD_Role_ID); // get Client details for role List <KeyNamePair> list = new List <KeyNamePair>(); KeyNamePair[] retValue = null; // String sql = "SELECT o.AD_Org_ID,o.Name,o.IsSummary " // 1..3 + "FROM AD_Role r, AD_Client c" + " INNER JOIN AD_Org o ON (c.AD_Client_ID=o.AD_Client_ID OR o.AD_Org_ID=0) " + "WHERE r.AD_Role_ID='" + AD_Role_ID + "'" // #1 + " AND c.AD_Client_ID='" + client.GetKey() + "'" // #2 + " AND o.IsActive='Y' AND o.IsSummary='N'" + " AND (r.IsAccessAllOrgs='Y' " + "OR (r.IsUseUserOrgAccess='N' AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_Role_OrgAccess ra " + "WHERE ra.AD_Role_ID=r.AD_Role_ID AND ra.IsActive='Y')) " + "OR (r.IsUseUserOrgAccess='Y' AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_User_OrgAccess ua " + "WHERE ua.AD_User_ID='" + AD_User_ID + "' AND ua.IsActive='Y'))" // #3 + ") " + "ORDER BY o.Name"; // MRole role = null; IDataReader dr = null; try { dr = DataBase.DB.ExecuteReader(sql); // load Orgs while (dr.Read()) { int AD_Org_ID = Utility.Util.GetValueOfInt(dr[0].ToString()); String Name = dr[1].ToString(); bool summary = "Y".Equals(dr[2].ToString()); if (summary) { if (role == null) { role = MRole.Get(m_ctx, AD_Role_ID, AD_User_ID, false); } GetOrgsAddSummary(list, AD_Org_ID, Name, role); } else { KeyNamePair p = new KeyNamePair(AD_Org_ID, Name); if (!list.Contains(p)) { list.Add(p); } } } dr.Close(); // retValue = new KeyNamePair[list.Count]; retValue = list.ToArray(); } catch { if (dr != null) { dr.Close(); } retValue = null; } // No Orgs if (retValue == null || retValue.Length == 0) { return(null); } // Client Info m_ctx.SetContext("#AD_Client_ID", client.GetKey()); m_ctx.SetContext("#AD_Client_Name", client.GetName()); Ini.SetProperty(Ini.P_CLIENT, client.GetName()); return(retValue); } // getOrgs
} // doWork /** * Process Alert * @param alert alert * @return true if processed */ private bool ProcessAlert(MAlert alert) { if (!alert.IsValid()) { log.Info("Invalid: " + alert); return(false); } log.Info("" + alert); m_recipients.Clear(); StringBuilder message = new StringBuilder(alert.GetAlertMessage()) .Append(Env.NL); // Context Ctx ctx = alert.GetCtx(); ctx.SetAD_Client_ID(alert.GetAD_Client_ID()); ctx.SetAD_Org_ID(alert.GetAD_Org_ID()); // bool valid = true; bool processed = false; MAlertRule[] rules = alert.GetRules(false); for (int i = 0; i < rules.Length; i++) { if (i > 0) { message.Append(Env.NL).Append("================================").Append(Env.NL); } //Trx trx = null; // assume r/o MAlertRule rule = rules[i]; if (!rule.IsValid()) { log.Config("Invalid: " + rule); continue; } log.Fine("" + rule); // Pre String sql = rule.GetPreProcessing(); if (sql != null && sql.Length > 0) { int no = DB.ExecuteQuery(sql); if (no == -1) { ValueNamePair error = VLogger.RetrieveError(); rule.SetErrorMsg("Pre=" + error.GetName()); m_errors.Append("Pre=" + error.GetName()); rule.SetIsValid(false); rule.Save(); valid = false; break; } } // Pre // The processing ctx.SetAD_Role_ID(0); ctx.SetAD_User_ID(0); sql = rule.GetSql(); if (alert.IsEnforceRoleSecurity() || alert.IsEnforceClientSecurity()) { int AD_Role_ID = alert.GetFirstAD_Role_ID(); if (AD_Role_ID == -1) { AD_Role_ID = alert.GetFirstUserAD_Role_ID(); } if (AD_Role_ID != -1) { String tableName = rule.GetTableName(); bool fullyQualified = MRole.SQL_FULLYQUALIFIED; if (Util.IsEmpty(tableName)) { fullyQualified = MRole.SQL_NOTQUALIFIED; } MRole role = MRole.Get(ctx, AD_Role_ID, 0, false); sql = role.AddAccessSQL(sql, tableName, fullyQualified, MRole.SQL_RO); ctx.SetAD_Role_ID(AD_Role_ID); } if (alert.GetFirstAD_User_ID() != -1) { ctx.SetAD_User_ID(alert.GetFirstAD_User_ID()); } } try { String text = ListSqlSelect(sql); if (text != null && text.Length > 0) { message.Append(text); processed = true; int index = text.IndexOf(":"); if (index > 0 && index < 5) { m_summary.Append(text.Substring(0, index)); } } } catch (Exception e) { rule.SetErrorMsg("Select=" + e.Message); m_errors.Append("Select=" + e.Message); rule.SetIsValid(false); rule.Save(); valid = false; break; } // Post sql = rule.GetPostProcessing(); if (sql != null && sql.Length > 0) { int no = DB.ExecuteQuery(sql); if (no == -1) { ValueNamePair error = VLogger.RetrieveError(); rule.SetErrorMsg("Post=" + error.GetName()); m_errors.Append("Post=" + error.GetName()); rule.SetIsValid(false); rule.Save(); valid = false; break; } } // Post } // for all rules // Update header if error if (!valid) { alert.SetIsValid(false); alert.Save(); return(false); } // Nothing to report if (!processed) { m_summary.Append(alert.GetName()).Append("=No Result - "); return(true); } // Send Message int countRecipient = 0; MAlertRecipient[] recipients = alert.GetRecipients(false); for (int i = 0; i < recipients.Length; i++) { MAlertRecipient recipient = recipients[i]; if (recipient.GetAD_User_ID() >= 0) // System == 0 { if (SendInfo(recipient.GetAD_User_ID(), alert, message.ToString())) { countRecipient++; } } if (recipient.GetAD_Role_ID() >= 0) // SystemAdministrator == 0 { MUserRoles[] urs = MUserRoles.GetOfRole(GetCtx(), recipient.GetAD_Role_ID()); for (int j = 0; j < urs.Length; j++) { MUserRoles ur = urs[j]; if (!ur.IsActive()) { continue; } if (SendInfo(ur.GetAD_User_ID(), alert, message.ToString())) { countRecipient++; } } } } m_summary.Append(alert.GetName()).Append(" (Recipients=").Append(countRecipient).Append(") - "); return(valid); } // processAlert
/** * Update/save Goals with Projects * @return true if updated */ private Boolean UpdateProjects() { if (!MEASURETYPE_Project.Equals(GetMeasureType()) || GetC_ProjectType_ID() == 0) { return(false); } MGoal[] goals = MGoal.GetMeasureGoals(GetCtx(), GetPA_Measure_ID()); for (int i = 0; i < goals.Length; i++) { MGoal goal = goals[i]; // Find Role MRole role = null; if (goal.GetAD_Role_ID() != 0) { role = MRole.Get(GetCtx(), goal.GetAD_Role_ID()); } else if (goal.GetAD_User_ID() != 0) { MUser user = MUser.Get(GetCtx(), goal.GetAD_User_ID()); MRole[] roles = user.GetRoles(goal.GetAD_Org_ID()); if (roles.Length > 0) { role = roles[0]; } } if (role == null) { role = MRole.GetDefault(GetCtx(), false); // could result in wrong data } // Decimal? ManualActual = null; MProjectType pt = MProjectType.Get(GetCtx(), GetC_ProjectType_ID()); String sql = pt.GetSqlPI(goal.GetRestrictions(false), goal.GetMeasureScope(), GetMeasureDataType(), null, role); IDataReader idr = null; try // SQL statement could be wrong { idr = DataBase.DB.ExecuteReader(sql, null, null); if (idr.Read()) { ManualActual = Utility.Util.GetValueOfDecimal(idr[0]); } idr.Close(); } catch (Exception e) { if (idr != null) { idr.Close(); } log.Log(Level.SEVERE, sql, e); } // SQL may return no rows or null if (ManualActual == null) { ManualActual = Env.ZERO; log.Fine("No Value = " + sql); } goal.SetMeasureActual(ManualActual); goal.Save(); } return(true); }
/** * Checks the access rights of the given role/client for the given document actions. * @param clientId * @param roleId * @param docTypeId * @param options * @param maxIndex * @return number of valid actions in the String[] options */ public static string[] checkActionAccess(Ctx ctx, int clientId, int roleId, int docTypeId, String[] options, ref int maxIndex) { return(MRole.Get(ctx, roleId).checkActionAccess(clientId, docTypeId, options, ref maxIndex)); }