示例#1
0
        public IActionResult Update([FromBody] ModuleModel model)
        {
            // Save module
            ModuleInfo module = new ModuleInfo();

            module.ModuleId    = model.Id;
            module.ModuleDefId = model.DefinitionId;
            module.PageId      = model.PageId;
            module.PlaceId     = model.PlaceId;
            module.Name        = model.Name;
            module.IsDisabled  = model.IsDisabled;

            _viewManager.SaveModule(module);

            // Handle static module
            if (model.IsStatic)
            {
                PlaceInfo place = _viewManager.GetPlace(model.PlaceId);
                place.ModuleId = module.ModuleId;
                _viewManager.SavePlace(place);
            }
            else if (model.Id > 0)
            {
                PlaceInfo place = _viewManager.GetPlace(model.PlaceId);

                if (place.ModuleId == module.ModuleId)
                {
                    place.ModuleId = null;
                    _viewManager.SavePlace(place);
                }
            }

            #region Permissions

            ModulePermissionInfo         modulePermission  = null;
            IList <ModulePermissionInfo> modulePermissions = _securityManager.GetModulePermissionsByModuleId(module.ModuleId);
            IList <PermissionInfo>       permissions       = _securityManager.GetPermissionsList();

            foreach (var permission in permissions)
            {
                if (model.Permissions.Contains(permission.PermissionId) &&
                    !modulePermissions.Any(mp => mp.PermissionId == permission.PermissionId))
                {
                    modulePermission              = new ModulePermissionInfo();
                    modulePermission.ModuleId     = module.ModuleId;
                    modulePermission.PermissionId = permission.PermissionId;

                    _securityManager.SaveModulePermission(modulePermission);
                }
                else if (!model.Permissions.Contains(permission.PermissionId) &&
                         modulePermissions.Any(mp => mp.PermissionId == permission.PermissionId))
                {
                    _securityManager.DeleteModulePermission(module.ModuleId, permission.PermissionId);
                }
            }

            #endregion

            return(Ok(new { module.ModuleId }));
        }
        public IActionResult Uninstall([FromBody] ModuleDefinitionModel model)
        {
            Assembly                     assembly           = null;
            ModuleDefinitionInfo         moduleDefinition   = null;
            IList <ModuleInfo>           modules            = null;
            IList <ModulePermissionInfo> modulesPermissions = null;

            if (model == null || String.IsNullOrEmpty(model.Name))
            {
                return(BadRequest());
            }

            // Get assembly with assembly name
            assembly = KastraAssembliesContext.Instance.GetModuleAssemblies()
                       .SingleOrDefault(a => a.GetName().Name == model.Name);

            if (assembly == null)
            {
                return(BadRequest("Module assembly not found"));
            }

            // Uninstall module
            _moduleManager.UninstallModule(assembly);

            // Get module definition
            moduleDefinition = _viewManager.GetModuleDef(model.Id, true);

            if (moduleDefinition == null)
            {
                return(BadRequest("Cannot find the module definition"));
            }

            modules = _viewManager.GetModulesList().Where(m => m.ModuleDefId == moduleDefinition.ModuleDefId).ToList();

            // Remove module controls
            foreach (ModuleControlInfo moduleControl in moduleDefinition.ModuleControls)
            {
                _viewManager.DeleteModuleControl(moduleControl.ModuleControlId);
            }

            // Remove all modules
            if (modules != null)
            {
                foreach (ModuleInfo module in modules)
                {
                    modulesPermissions = _securityManager.GetModulePermissionsByModuleId(module.ModuleId);

                    if (modulesPermissions != null)
                    {
                        foreach (ModulePermissionInfo modulePermission in modulesPermissions)
                        {
                            _securityManager.DeleteModulePermission(modulePermission.ModulePermissionId);
                        }
                    }

                    _viewManager.DeleteModule(module.ModuleId);
                }
            }

            // Remove module definition
            _viewManager.DeleteModuleDef(moduleDefinition.ModuleDefId);

            return(Ok());
        }