public void GenerateActivateEvents()
 {
     //TEMP: This is really part of the extension manager's job.
     var extensions = _extensionManager.ActiveExtensions_Obsolete().ToReadOnlyCollection();
     foreach (var extension in extensions) {
         var context = new ExtensionEventContext {
                                                     Extension = extension,
                                                     EnabledExtensions = extensions,
                                                 };
         _extensionEvents.Invoke(x => x.Activating(context), Logger);
         _extensionEvents.Invoke(x => x.Activated(context), Logger);
     }
 }
Ejemplo n.º 2
0
        public override void Enabled(ExtensionEventContext context) {
            var extensionDisplayName = context.Extension.Descriptor.DisplayName ?? context.Extension.Descriptor.Name;

            // when another module is being enabled, locate matching permission providers
            var providersForEnabledModule =
                _permissionProviders.Where(x => x.ModuleName == extensionDisplayName);

            if (providersForEnabledModule.Any()) {
                Logger.Debug("Configuring default roles for module {0}", extensionDisplayName);
            }
            else {
                Logger.Debug("No default roles for module {0}", extensionDisplayName);
            }

            foreach (var permissionProvider in providersForEnabledModule) {
                // get and iterate stereotypical groups of permissions
                var stereotypes = permissionProvider.GetDefaultStereotypes();
                foreach (var stereotype in stereotypes) {

                    // turn those stereotypes into roles
                    var role = _roleService.GetRoleByName(stereotype.Name);
                    if (role == null) {
                        Logger.Information("Defining new role {0} for permission stereotype", stereotype.Name);

                        _roleService.CreateRole(stereotype.Name);
                        role = _roleService.GetRoleByName(stereotype.Name);
                    }

                    // and merge the stereotypical permissions into that role                    
                    var stereotypePermissionNames = (stereotype.Permissions ?? Enumerable.Empty<Permission>()).Select(x => x.Name);
                    var currentPermissionNames = role.RolesPermissions.Select(x => x.Permission.Name);

                    var distinctPermissionNames = currentPermissionNames
                        .Union(stereotypePermissionNames)
                        .Distinct();


                    // update role if set of permissions has increased
                    var additionalPermissionNames = distinctPermissionNames.Except(currentPermissionNames);

                    if (additionalPermissionNames.Any()) {
                        foreach (var permissionName in additionalPermissionNames) {
                            Logger.Information("Default role {0} granted permission {1}", stereotype.Name, permissionName);
                            _roleService.CreatePermissionForRole(role.Name, permissionName);
                        }                        
                    }
                }
            }
        }
 public void GenerateInstallEvents()
 {
     //TEMP: this is really part of the extension manager's job. an extension
     // install event is being simulated here on each web app startup
     var enabled = new List<ExtensionEntry>();
     foreach (var extension in _extensionManager.ActiveExtensions_Obsolete()) {
         var context = new ExtensionEventContext {
                                                     Extension = extension,
                                                     EnabledExtensions = enabled.ToReadOnlyCollection(),
                                                 };
         _extensionEvents.Invoke(x => x.Enabling(context), Logger);
         enabled.Add(extension);
         context.EnabledExtensions = enabled.ToReadOnlyCollection();
         _extensionEvents.Invoke(x => x.Enabled(context), Logger);
     }
 }
 public override void Activated(ExtensionEventContext context) {
     if (context.Extension.Descriptor.Name == "Orchard.Pages") {
         Refresh();
     }
 }
 public virtual void Enabling(ExtensionEventContext context)
 {
 }
 public virtual void Disabled(ExtensionEventContext context)
 {
 }
 public virtual void Deactivating(ExtensionEventContext context)
 {
 }
 public virtual void Activated(ExtensionEventContext context)
 {
 }