void DoPrivilegeCreate()
        {
            AxSecurityPrivilege privilege;

            privilege = _axHelper.MetadataProvider.SecurityPrivileges.Read(ObjectName);
            if (privilege != null)
            {
                throw new Exception($"Privilege {ObjectName} already exists");
            }
            privilege = new AxSecurityPrivilege();
            AxSecurityEntryPointReference entryPoint = new AxSecurityEntryPointReference();

            entryPoint.Name       = MenuItemName;
            entryPoint.Grant      = GetGrant();
            entryPoint.ObjectName = MenuItemName;
            entryPoint.ObjectType = MenuItemType;

            privilege.Name = ObjectName;
            privilege.EntryPoints.Add(entryPoint);
            privilege.Label = FormLabel;

            _axHelper.MetaModelService.CreateSecurityPrivilege(privilege, _axHelper.ModelSaveInfo);
            _axHelper.AppendToActiveProject(privilege);

            AddLog($"Privilege: {privilege.Name}; ");
        }
Esempio n. 2
0
        void DoPrivilegeCreateSingle(string privilegeName, string privilegeLabel, AccessGrant accessGrant)
        {
            if (String.IsNullOrWhiteSpace(privilegeLabel))
            {
                return;
            }

            AxSecurityPrivilege privilege;

            privilege = _axHelper.MetadataProvider.SecurityPrivileges.Read(privilegeName);
            if (privilege != null)
            {
                return;
            }
            privilege = new AxSecurityPrivilege();
            AxSecurityEntryPointReference entryPoint = new AxSecurityEntryPointReference();

            entryPoint.Name       = FormName;
            entryPoint.Grant      = accessGrant;
            entryPoint.ObjectName = FormName;
            entryPoint.ObjectType = EntryPointType.MenuItemDisplay;

            privilege.Name = privilegeName;
            privilege.EntryPoints.Add(entryPoint);
            privilege.Label = privilegeLabel;

            _axHelper.MetaModelService.CreateSecurityPrivilege(privilege, _axHelper.ModelSaveInfo);
            _axHelper.AppendToActiveProject(privilege);

            AddLog($"Privilege: {privilege.Name}; ");
        }
        private void createSecurityElement_FromDataEntity(IDataEntityView selectedDataEntity, string suffix)
        {
            //Create Security privilege
            AxSecurityPrivilege axSecurityPriv = new AxSecurityPrivilege()
            {
                Name = selectedDataEntity.Name + suffix
            };

            axSecurityPriv.DataEntityPermissions.Add(
                new AxSecurityDataEntityPermission()
            {
                Grant = suffix == "Maintain"
                            ? Microsoft.Dynamics.AX.Metadata.Core.MetaModel.AccessGrant.ConstructGrantDelete()
                            : Microsoft.Dynamics.AX.Metadata.Core.MetaModel.AccessGrant.ConstructGrantRead(),
                Name = selectedDataEntity.Name
            });

            // Find current model
            var modelSaveInfo = Common.CommonUtil.GetCurrentModelSaveInfo();

            var metaModelService = Common.CommonUtil.GetModelSaveService();

            metaModelService.CreateSecurityPrivilege(axSecurityPriv, modelSaveInfo);

            Common.CommonUtil.AddElementToProject(axSecurityPriv);
        }
Esempio n. 4
0
        protected override void Create()
        {
            var element = new AxSecurityPrivilege {
                Name = ElementName
            };

            MetaService.CreateSecurityPrivilege(element, Model);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates privilege in AOT
        /// </summary>
        /// <param name="name">Privilege's name</param>
        /// <param name="grant">User chosen privilege access level</param>
        /// <remarks>This method could be improved. Most probably are better ways to achieve this goal.</remarks>
        protected void create(string name, AccessGrant grant)
        {
            AxSecurityPrivilege           privilege  = new AxSecurityPrivilege();
            AxSecurityEntryPointReference entryPoint = new AxSecurityEntryPointReference();
            ModelInfo     modelInfo;
            ModelSaveInfo modelSaveInfo = new ModelSaveInfo();
            VSProjectNode project       = Utils.LocalUtils.GetActiveProject();

            #region Create entry point
            entryPoint.Name       = this.menuItem.Name;
            entryPoint.Grant      = grant;
            entryPoint.ObjectName = this.menuItem.Name;

            switch (this.menuItem.ObjectType)
            {
            case MenuItemObjectType.Form:
                entryPoint.ObjectType = EntryPointType.MenuItemDisplay;
                break;

            case MenuItemObjectType.Class:
                entryPoint.ObjectType = EntryPointType.MenuItemAction;
                break;

            case MenuItemObjectType.SSRSReport:
                entryPoint.ObjectType = EntryPointType.MenuItemOutput;
                break;

            default:
                throw new NotImplementedException($"Menuitem object type {this.menuItem.ObjectType} is not implemented.");
            }

            #endregion

            #region Create privilege
            privilege.Name = name;
            privilege.EntryPoints.Add(entryPoint);
            privilege.Label = this.menuItem.Label;
            #endregion

            // Most probably there is a better way to do this part.
            #region Add to AOT
            modelInfo = project.GetProjectsModelInfo();

            modelSaveInfo.Id    = modelInfo.Id;
            modelSaveInfo.Layer = modelInfo.Layer;

            var metaModelProviders = ServiceLocator.GetService(typeof(IMetaModelProviders)) as IMetaModelProviders;
            var metaModelService   = metaModelProviders.CurrentMetaModelService;

            metaModelService.CreateSecurityPrivilege(privilege, modelSaveInfo);
            #endregion

            this.appendToProject(privilege);
        }
        private void createSecurityElement_FromDataEntity(IDataEntityView selectedDataEntity, string suffix)
        {
            //Create Security privilege
            AxSecurityPrivilege axSecurityPriv = new AxSecurityPrivilege()
            {
                Name = selectedDataEntity.Name + suffix
            };

            axSecurityPriv.DataEntityPermissions.Add(
                new AxSecurityDataEntityPermission()
            {
                Grant = suffix == "Maintain"
                            ? Microsoft.Dynamics.AX.Metadata.Core.MetaModel.AccessGrant.ConstructGrantDelete()
                            : Microsoft.Dynamics.AX.Metadata.Core.MetaModel.AccessGrant.ConstructGrantRead(),
                Name = selectedDataEntity.Name
            });

            // Assign the correct label on this by addint maintain or view in the label, copy the base label from the menu item
            string label = selectedDataEntity.Label;

            if (label.StartsWith("@"))
            {
                //label = Labels.LabelHelper.FindLabel(label).LabelText;
                label = Labels.LabelHelper.FindLabelGlobally(label).LabelText;
            }

            if (suffix.Equals("Maintain"))
            {
                label = "Maintain " + label;
            }
            else if (suffix.Equals("View"))
            {
                label = "View " + label;
            }
            // Convert to camel case
            if (String.IsNullOrEmpty(label) == false)
            {
                char[] a = label.ToLowerInvariant().ToCharArray();
                a[0]  = char.ToUpperInvariant(a[0]);
                label = new String(a);
            }
            axSecurityPriv.Label = label;

            // Find current model
            var modelSaveInfo = Common.CommonUtil.GetCurrentModelSaveInfo();

            var metaModelService = Common.CommonUtil.GetModelSaveService();

            metaModelService.CreateSecurityPrivilege(axSecurityPriv, modelSaveInfo);

            Common.CommonUtil.AddElementToProject(axSecurityPriv);
        }
Esempio n. 7
0
        /// <summary>
        /// Append createds privilege to active project
        /// </summary>
        /// <param name="privilege">Recently created privilege</param>
        /// <remarks>This method could be improved. Most probably are better ways to achieve this goal.</remarks>
        protected void appendToProject(AxSecurityPrivilege privilege)
        {
            DTE dte = CoreUtility.ServiceProvider.GetService(typeof(DTE)) as DTE;

            if (dte == null)
            {
                throw new NotSupportedException(string.Format(CultureInfo.InvariantCulture, "No service for DTE found. The DTE must be registered as a service for using this API.", new object[0]));
            }
            VSProjectNode activeProjectNode = PrivilegeEngine.GetActiveProjectNode(dte);

            activeProjectNode.AddModelElementsToProject(new List <MetadataReference>
            {
                new MetadataReference(privilege.Name, privilege.GetType())
            });
            //var projectService = ServiceLocator.GetService(typeof(IDynamicsProjectService)) as IDynamicsProjectService;
            //projectService.AddElementToActiveProject(privilege);
        }
Esempio n. 8
0
        public static void Create(UtilElementType type, string name)
        {
            if (Project == null)
            {
                throw new InvalidOperationException("No project selected.");
            }

            _name = name;
            switch (type)
            {
            case UtilElementType.DisplayTool:
                var existsDisplayTool = LocalUtils.MetaService.GetMenuItemDisplayNames().Contains(name);

                if (!existsDisplayTool)
                {
                    var displayMenu = new AxMenuItemDisplay {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateMenuItemDisplay(displayMenu, Model);
                    AddAotElement <AxMenuItemDisplay>();
                }

                break;

            case UtilElementType.OutputTool:
                var existsOutputTool = LocalUtils.MetaService.GetMenuItemDisplayNames().Contains(name);

                if (!existsOutputTool)
                {
                    var outputMenu = new AxMenuItemOutput {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateMenuItemOutput(outputMenu, Model);
                    AddAotElement <AxMenuItemOutput>();
                }

                break;

            case UtilElementType.ActionTool:
                var existsActionTool = LocalUtils.MetaService.GetMenuItemDisplayNames().Contains(name);

                if (!existsActionTool)
                {
                    var actionMenu = new AxMenuItemAction {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateMenuItemAction(actionMenu, Model);
                    AddAotElement <AxMenuItemAction>();
                }
                break;

            case UtilElementType.Query:
                var existsQuery = LocalUtils.MetaService.GetQueryNames().Contains(name);

                if (!existsQuery)
                {
                    var query = new AxQuerySimple {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateQuery(query, Model);
                    AddAotElement <AxQuerySimple>();
                }
                break;

            case UtilElementType.Enum:
                var Enum = LocalUtils.MetaService.GetEnumNames().Contains(name);

                if (!Enum)
                {
                    var edtEnum = new AxEnum {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateEnum(edtEnum, Model);
                    AddAotElement <AxEnum>();
                }
                break;

            case UtilElementType.ExtendedType:



                break;

            case UtilElementType.Table:
                var existsTable = LocalUtils.MetaService.GetTableNames().Contains(name);

                if (!existsTable)
                {
                    var table = new AxTable {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateTable(table, Model);
                    AddAotElement <AxTable>();
                }
                break;

            case UtilElementType.Class:
                var existsClass = LocalUtils.MetaService.GetClassNames().Contains(name);

                if (!existsClass)
                {
                    var axClass = new AxClass {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateClass(axClass, Model);
                    AddAotElement <AxClass>();
                }
                break;

            case UtilElementType.SSRSReport:
                var existsSsrsReport = LocalUtils.MetaService.GetReportNames().Contains(name);

                if (!existsSsrsReport)
                {
                    var srsReport = new AxReport {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateReport(srsReport, Model);
                    AddAotElement <AxReport>();
                }
                break;

            case UtilElementType.Form:
                var existsForm = LocalUtils.MetaService.GetFormNames().Contains(name);

                if (!existsForm)
                {
                    var axForm = new AxForm {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateForm(axForm, Model);
                    AddAotElement <AxForm>();
                }
                break;

            case UtilElementType.Menu:
                var existsMenu = LocalUtils.MetaService.GetMenuNames().Contains(name);

                if (!existsMenu)
                {
                    var axMenu = new AxMenu {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateMenu(axMenu, Model);
                    AddAotElement <AxMenu>();
                }
                break;

            case UtilElementType.SecDuty:
                var existsSecDuty = LocalUtils.MetaService.GetSecurityDutyNames().Contains(name);

                if (!existsSecDuty)
                {
                    var axDuty = new AxSecurityDuty {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateSecurityDuty(axDuty, Model);
                    AddAotElement <AxSecurityDuty>();
                }
                break;

            case UtilElementType.SecPolicy:
                var existsSecPolicy = LocalUtils.MetaService.GetSecurityPolicyNames().Contains(name);

                if (!existsSecPolicy)
                {
                    var axPolicy = new AxSecurityPolicy {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateSecurityPolicy(axPolicy, Model);
                    AddAotElement <AxSecurityPolicy>();
                }
                break;

            case UtilElementType.SecPrivilege:
                var existsSecPrivilege = LocalUtils.MetaService.GetSecurityPrivilegeNames().Contains(name);

                if (!existsSecPrivilege)
                {
                    var privilege = new AxSecurityPrivilege {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateSecurityPrivilege(privilege, Model);
                    AddAotElement <AxSecurityPrivilege>();
                }
                break;

            case UtilElementType.SecRole:
                var existsSecRole = LocalUtils.MetaService.GetSecurityRoleNames().Contains(name);

                if (!existsSecRole)
                {
                    var role = new AxSecurityRole {
                        Name = name
                    };
                    LocalUtils.MetaService.CreateSecurityRole(role, Model);
                    AddAotElement <AxSecurityRole>();
                }
                break;

            default:
                throw new Exception("Element not supported");
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Appends created privilege to active project
        /// </summary>
        /// <param name="privilege">Recently created privilege</param>
        /// <remarks>This method could be improved. Most probably are better ways to achieve this goal.</remarks>
        protected void appendToProject(AxSecurityPrivilege privilege)
        {
            var projectService = ServiceLocator.GetService(typeof(IDynamicsProjectService)) as IDynamicsProjectService;

            projectService.AddElementToActiveProject(privilege);
        }
        private string createSecurityElement_FromMenuItem(
            IMenuItem selectedMenuItem,
            Microsoft.Dynamics.AX.Metadata.Core.MetaModel.EntryPointType entryPointType,
            string suffix)
        {
            // Find project to work with
            //VSProjectNode project = LocalUtils.GetActiveProject();

            //Create Security privilege
            AxSecurityPrivilege axSecurityPrivMaint = new AxSecurityPrivilege()
            {
                Name = selectedMenuItem.Name + suffix
            };

            axSecurityPrivMaint.EntryPoints.Add(
                new AxSecurityEntryPointReference()
            {
                ObjectType = entryPointType,
                ObjectName = selectedMenuItem.Name,
                Name       = selectedMenuItem.Name,
                Grant      = new Microsoft.Dynamics.AX.Metadata.Core.MetaModel.AccessGrant()
                {
                    Delete = suffix.Equals("Maintain")
                                                    ? Microsoft.Dynamics.AX.Metadata.Core.MetaModel.AccessGrantPermission.Allow
                                                    : Microsoft.Dynamics.AX.Metadata.Core.MetaModel.AccessGrantPermission.Unset,
                    Read = suffix.Equals("View")
                                                    ? Microsoft.Dynamics.AX.Metadata.Core.MetaModel.AccessGrantPermission.Allow
                                                    : Microsoft.Dynamics.AX.Metadata.Core.MetaModel.AccessGrantPermission.Unset
                }
            });

            // Assign the correct label on this by addint maintain or view in the label, copy the base label from the menu item
            string label = selectedMenuItem.Label;

            if (label.StartsWith("@"))
            {
                label = Labels.LabelHelper.FindLabelGlobally(label).LabelText;
            }

            if (suffix.Equals("Maintain"))
            {
                label = "Maintain " + label;
            }
            else if (suffix.Equals("View"))
            {
                label = "View " + label;
            }
            // Convert to camel case
            if (String.IsNullOrEmpty(label) == false)
            {
                char[] a = label.ToLowerInvariant().ToCharArray();
                a[0]  = char.ToUpperInvariant(a[0]);
                label = new String(a);
            }
            axSecurityPrivMaint.Label = label;


            // Find current model
            var modelSaveInfo = Common.CommonUtil.GetCurrentModelSaveInfo();

            //Create item in the right model
            var metaModelProviders = ServiceLocator.GetService <IMetaModelProviders>() as IMetaModelProviders;
            var metaModelService   = metaModelProviders.CurrentMetaModelService;

            metaModelService.CreateSecurityPrivilege(axSecurityPrivMaint, modelSaveInfo);
            //metaModelService.CreateClass(axClass, saveInfo);

            // Add the class to the active project
            //var projectService = ServiceLocator.GetService(typeof(IDynamicsProjectService)) as IDynamicsProjectService;
            //projectService.AddElementToActiveProject(axSecurityPrivMaint);
            Common.CommonUtil.AddElementToProject(axSecurityPrivMaint);

            // Common.CommonUtil.ShowLog($"Security privilege: {axSecurityPrivMaint} created");

            return(axSecurityPrivMaint.Name);
        }