Example #1
0
        /// <summary>
        /// checks if the user has access to the navigation node
        /// </summary>
        public static bool HasAccessPermission(XmlNode ANode, string AUserId, bool ACheckLedgerPermissions)
        {
            // TODO: if this is an action node, eg. opens a screen, check the static function that tells RequiredPermissions of the screen

            string PermissionsRequired = TXMLParser.GetAttributeRecursive(ANode, "PermissionsRequired", true);

            while (PermissionsRequired.Length > 0)
            {
                string PermissionRequired = StringHelper.GetNextCSV(ref PermissionsRequired);

                if (!UserInfo.GUserInfo.IsInModule(PermissionRequired))
                {
                    return(false);
                }
            }

            if (ACheckLedgerPermissions)
            {
                if (TXMLParser.GetAttributeRecursive(ANode, "DependsOnLedger", true).ToLower() == "true")
                {
                    // check if the user has permissions for this ledger
                    Int32 LedgerNumber = TXMLParser.GetIntAttribute(ANode, "LedgerNumber");

                    if (LedgerNumber != -1)
                    {
                        if (!UserInfo.GUserInfo.IsInModule(FormatLedgerNumberForModuleAccess(LedgerNumber)))
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// checks if the user has access to the navigation node
        /// </summary>
        public bool HasAccessPermission(XmlNode ANode, TPetraPrincipal AUserInfo)
        {
            // TODO: if this is an action node, eg. opens a screen, check the static function that tells RequiredPermissions of the screen

            string PermissionsRequired = TXMLParser.GetAttributeRecursive(ANode, "PermissionsRequired", true);

            while (PermissionsRequired.Length > 0)
            {
                string PermissionRequired = StringHelper.GetNextCSV(ref PermissionsRequired);

                if (!AUserInfo.IsInModule(PermissionRequired))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #3
0
        public void TestLoopThroughUINavigation()
        {
            TLogging.Log("Running test 'TestLoopThroughUINavigation'..." + Environment.NewLine);

            // get all nodes that have an attribute ActionOpenScreen
            XPathExpression   expr     = FNavigator.Compile("//*[@ActionOpenScreen]");
            XPathNodeIterator iterator = FNavigator.Select(expr);

            while (iterator.MoveNext())
            {
                if (iterator.Current is IHasXmlNode)
                {
                    XmlNode ActionNode = ((IHasXmlNode)iterator.Current).GetNode();

                    // look at the permissions module the window came from
                    string Module = TXMLParser.GetAttributeRecursive(ActionNode, "PermissionsRequired", true);
                    TLogging.Log(String.Format("{0,-36}{1,-36}{2}", ActionNode.Name, ActionNode.Attributes["ActionOpenScreen"].Value, Module));
                }
            }
        }
Example #4
0
        /// <summary>
        /// checks if the user has access to the navigation node
        /// </summary>
        public bool HasAccessPermission(XmlNode ANode, TPetraPrincipal AUserInfo)
        {
            // TODO: if this is an action node, eg. opens a screen, check the static function that tells RequiredPermissions of the screen

            string PermissionsRequired = TXMLParser.GetAttributeRecursive(ANode, "PermissionsRequired", true);

            try
            {
                if (PermissionsRequired.StartsWith("\"") && PermissionsRequired.EndsWith("\""))
                {
                    PermissionsRequired = PermissionsRequired.Substring(1, PermissionsRequired.Length - 2);
                }

                if (PermissionsRequired.Contains(",") && !PermissionsRequired.EndsWith(")"))
                {
                    PermissionsRequired = "AND(" + PermissionsRequired + ")";
                }

                if (PermissionsRequired == "")
                {
                    PermissionsRequired = "USER";
                }

                TSecurityChecks.CheckUserModulePermissions(PermissionsRequired, "UINavigation");
                return(true);
            }
            catch (ESecurityModuleAccessDeniedException)
            {
                return(false);
            }
            catch (ArgumentException e)
            {
                TLogging.Log("Issue for node " + ANode.Name + Environment.NewLine +
                             e.ToString());
                return(false);
            }
        }
Example #5
0
        private Dictionary <string, object> GetChildItems(XmlNode AFolderNode, string APath, TPetraPrincipal AUserInfo)
        {
            Dictionary <string, object> items = new Dictionary <string, object>();

            foreach (XmlNode child in AFolderNode.ChildNodes)
            {
                if (!HasAccessPermission(child, AUserInfo))
                {
                    continue;
                }

                Dictionary <string, object> item = new Dictionary <string, object>();
                item.Add("caption", GetCaption(child, true));
                if (child.ChildNodes.Count > 0)
                {
                    item.Add("items", GetChildItems(child, APath + "/" + child.Name, AUserInfo));
                }
                else
                {
                    item.Add("form", child.Name);
                }

                string Action = TXMLParser.GetAttribute(child, "Action");

                if (Action.Length > 0)
                {
                    item.Add("action", Action);
                }

                string Icon = TXMLParser.GetAttributeRecursive(child, "fa-icon", false);

                if (Icon.Length > 0)
                {
                    item.Add("icon", Icon);
                }

                string form = TXMLParser.GetAttribute(child, "Form");

                if (form.Length > 0)
                {
                    item["form"] = form;
                }

                string path = TXMLParser.GetAttributeRecursive(child, "Path", false);

                if (path.Length == 0)
                {
                    path = APath;
                }

                item.Add("path", path);

                if (File.Exists(TAppSettingsManager.GetValue("Forms.Path") + "/" + path.Replace('_', '/') + "/" + child.Name + ".html"))
                {
                    item["htmlexists"] = true;
                }

                items.Add(child.Name, item);
            }

            return(items);
        }
Example #6
0
        /// <summary>
        /// verify that all windows open either without error or with proper exception handling
        /// </summary>
        private void TestOpenAllWindows()
        {
            TLogging.Log(String.Format("Running test 'TestOpenAllWindows' with Culture '{0}'...",
                                       Thread.CurrentThread.CurrentCulture.ToString()) + Environment.NewLine);

            // get all nodes that have an attribute ActionOpenScreen
            XPathExpression   expr     = FNavigator.Compile("//*[@ActionOpenScreen]");
            XPathNodeIterator iterator = FNavigator.Select(expr);

            //create counter variables to keep track of number of failures (might do with lists soon...for modules(?))
            int NoSysManPermissionCount = 0;
            int NoOtherPermissionCount  = 0;
            int BadFailures             = 0;
            int TotalWindowsOpened      = 0;

            List <String> notOpened         = new List <String>();
            List <String> sysManPermissions = new List <String>();
            List <String> otherPermissions  = new List <String>();
            List <String> workingWindows    = new List <String>();

            while (iterator.MoveNext())
            {
                if (iterator.Current is IHasXmlNode)
                {
                    XmlNode ActionNode = ((IHasXmlNode)iterator.Current).GetNode();

                    string className = ActionNode.Attributes["ActionOpenScreen"].Value;

                    if (className == "TFrmBankStatementImport")
                    {
                        // skip this one because it pops up an additional dialog that requires user input
                        continue;
                    }

                    // look at the permissions module the window came from
                    string Module = TYml2Xml.GetAttributeRecursive(ActionNode, "PermissionsRequired");

                    TLstTasks.CurrentLedger = TFrmMainWindowNew.CurrentLedger;

                    // Try to open each screen and log the screens that cannot open
                    try
                    {
                        Assert.AreEqual(String.Empty,
                                        TLstTasks.ExecuteAction(ActionNode, null));

                        if (TLstTasks.LastOpenedScreen != null)
                        {
                            TLstTasks.LastOpenedScreen.Close();
                        }

                        TotalWindowsOpened++;
                        string WindowAndModule = ActionNode.Name + Environment.NewLine + "            Permission Required: " +
                                                 Module;
                        workingWindows.Add(WindowAndModule);

                        //make sure the user had the permissions to open the windows that it opened
                        if (!UserInfo.GUserInfo.IsInModule(Module) && !Module.Contains(""))
                        {
                            BadFailures++;
                            workingWindows.Add("User did not have permission to access " + Module);
                        }
                    }
                    catch (AssertionException e)
                    {
                        TLogging.Log("Window can't be opened: " + ActionNode.Name + " " + ActionNode.Attributes["ActionOpenScreen"].Value +
                                     Environment.NewLine + e.ToString());

                        // if the failure is a permission failure, just log it but don't fail the test
                        if (Catalog.GetString("Sorry, you don't have enough permissions to do this") ==
                            TLstTasks.ExecuteAction(ActionNode, null))
                        {
                            // make sure user didn't have the necessary permissions to open that window
                            // true means user should have been able to open without error
                            if (UserInfo.GUserInfo.IsInModule(Module))
                            {
                                BadFailures++;
                                string whyFailed = "User should have been able to open " + ActionNode.Name + " with his " +
                                                   Module + " permission...";
                                notOpened.Add(whyFailed);
                            }
                            else
                            {
                                string permissions     = TYml2Xml.GetAttributeRecursive(ActionNode, "PermissionsRequired");
                                string WindowAndModule = ActionNode.Name + Environment.NewLine + "            Permission Required: " + permissions;

                                if (permissions.Contains("SYSMAN"))
                                {
                                    NoSysManPermissionCount++;
                                    sysManPermissions.Add(WindowAndModule);
                                }
                                else
                                {
                                    NoOtherPermissionCount++;
                                    otherPermissions.Add(WindowAndModule);
                                }
                            }
                        }
                        else
                        {
                            BadFailures++;

                            string WindowAndModule = ActionNode.Name + Environment.NewLine + "            Permission Required: " +
                                                     TYml2Xml.GetAttributeRecursive(ActionNode, "PermissionsRequired");

                            notOpened.Add(WindowAndModule);
                        }
                    }
                    // if the exception has to due with a ledger that the user doesn't have permission to access,
                    // make it a permission exception. Else, fail the test.
                    catch (Exception e)
                    {
                        TLogging.Log("Window can't be opened: " + ActionNode.Name + " " + ActionNode.Attributes["ActionOpenScreen"].Value +
                                     Environment.NewLine + e.ToString());

                        string ledgerNumber = TXMLParser.GetAttributeRecursive(ActionNode, "LedgerNumber", true);
                        string ledger       = "LEDGER00" + ledgerNumber;

                        if ((ledgerNumber != String.Empty) && !UserInfo.GUserInfo.IsInModule(ledger))
                        {
                            NoOtherPermissionCount++;
                            string WindowAndModule = ActionNode.Name + Environment.NewLine + "            Permission Required: " +
                                                     TYml2Xml.GetAttributeRecursive(ActionNode, "PermissionsRequired") +
                                                     Environment.NewLine +
                                                     "                                 " + ledger;
                            otherPermissions.Add(WindowAndModule);
                        }
                        else
                        {
                            BadFailures++;
                            string WindowAndModule = ActionNode.Name + Environment.NewLine + "            Permission Required: " +
                                                     TYml2Xml.GetAttributeRecursive(ActionNode, "PermissionsRequired");

                            if (ledgerNumber != String.Empty)
                            {
                                WindowAndModule += (Environment.NewLine +
                                                    "                                 " + ledger);
                            }

                            notOpened.Add(WindowAndModule);
                        }
                    }
                }
            }

            //Give stats about where failures were
            //feel free to change any formatting, I'm not in love with it right now
            string notOpenedString         = string.Join(Environment.NewLine + "      ", notOpened.ToArray());
            string sysManPermissionsString = string.Join(Environment.NewLine + "      ", sysManPermissions.ToArray());
            string otherPermissionsString  = string.Join(Environment.NewLine + "      ", otherPermissions.ToArray());
            string workingWindowsString    = string.Join(Environment.NewLine + "      ", workingWindows.ToArray());

            //print the permissions the user should have
            TLogging.Log(Environment.NewLine + Environment.NewLine + "User Permissions: " + Environment.NewLine +
                         UserInfo.GUserInfo.GetPermissions());

            TLogging.Log(Environment.NewLine + Environment.NewLine + "Statistics: " + Environment.NewLine + "Number of windows opened: " +
                         TotalWindowsOpened + Environment.NewLine + "      " + workingWindowsString + Environment.NewLine +
                         Environment.NewLine + Environment.NewLine + Environment.NewLine + "SYSMAN Permission Exceptions: " +
                         sysManPermissions.Count + Environment.NewLine + "      " + sysManPermissionsString + Environment.NewLine +
                         Environment.NewLine + Environment.NewLine + Environment.NewLine + "Other Permission Exceptions: " +
                         otherPermissions.Count + Environment.NewLine + "      " + otherPermissionsString + Environment.NewLine +
                         Environment.NewLine + Environment.NewLine + "Windows that should be opened but couldn't: " +
                         notOpened.Count + Environment.NewLine + "      " + notOpenedString + Environment.NewLine);

            //Now the loop is finished so fail if there were exceptions
            Assert.GreaterOrEqual(TotalWindowsOpened, 190, "Expected to open at least 190 windows");
            Assert.GreaterOrEqual(sysManPermissions.Count, 3, "Expected to fail to open at least 3 windows requiring SYSMAN permissions");
            Assert.AreEqual(notOpened.Count, 0, "Failed to open at least one window for unexplained reasons");
            Assert.AreEqual(otherPermissions.Count,
                            0,
                            "Unexpected failure to open some windows due to a permissions error, when we should have had sufficient permission");

            if (BadFailures > 0)
            {
                Assert.Fail(String.Format("General failure to successfully open {0} window(s).  Maybe there was an exception??", BadFailures));
            }
        }