mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
#17289: only allowing default tenant site administrator to install packages by default. Others can be granted permission.
--HG-- branch : dev rename : src/Orchard.Tests.Modules/Packaging/Hello.World.csproj.txt => src/Orchard.Tests.Modules/Packaging/Services/Hello.World.csproj.txt rename : src/Orchard.Tests.Modules/Packaging/HelloDriver.cs.txt => src/Orchard.Tests.Modules/Packaging/Services/HelloDriver.cs.txt rename : src/Orchard.Tests.Modules/Packaging/PackageBuilderTests.cs => src/Orchard.Tests.Modules/Packaging/Services/PackageBuilderTests.cs
This commit is contained in:
@@ -39,7 +39,7 @@ namespace Orchard.Tests.Modules.CodeGeneration.Commands {
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
builder.RegisterInstance(new ShellBlueprint());
|
||||
builder.RegisterInstance(new ShellSettings { Name = "Default", DataTablePrefix = "Test", DataProvider = "SqlCe" });
|
||||
builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataTablePrefix = "Test", DataProvider = "SqlCe" });
|
||||
builder.RegisterInstance(dataServicesProviderFactory).As<IDataServicesProviderFactory>();
|
||||
builder.RegisterInstance(AppDataFolderTests.CreateAppDataFolder(Path.GetDirectoryName(databaseFileName))).As<IAppDataFolder>();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.FileSystems.Media;
|
||||
using Orchard.Media.Models;
|
||||
@@ -31,7 +32,6 @@ namespace Orchard.Tests.Modules.Media.Services {
|
||||
private const string NoExtensionFileName = "test";
|
||||
|
||||
private const string MediaFolder = "Media";
|
||||
private const string ShellSettingsName = "Default";
|
||||
|
||||
private StubOrchardServices OrchardServices { get; set; }
|
||||
private StubStorageProvider StorageProvider { get; set; }
|
||||
@@ -40,15 +40,15 @@ namespace Orchard.Tests.Modules.Media.Services {
|
||||
[SetUp]
|
||||
public void Setup() {
|
||||
OrchardServices = new StubOrchardServices();
|
||||
StorageProvider = new StubStorageProvider(new ShellSettings { Name = ShellSettingsName });
|
||||
StorageProvider = new StubStorageProvider(new ShellSettings { Name = ShellSettings.DefaultName });
|
||||
MediaService = new MediaServiceAccessor(StorageProvider, OrchardServices);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPublicUrlTests() {
|
||||
Assert.That(() => MediaService.GetPublicUrl(null), Throws.InstanceOf(typeof(ArgumentException)), "null relative path is invalid");
|
||||
Assert.That(MediaService.GetPublicUrl(TextFileName), Is.EqualTo(string.Format("/{0}/{1}/{2}", MediaFolder, ShellSettingsName, TextFileName)), "base path file");
|
||||
Assert.That(MediaService.GetPublicUrl(string.Format("{0}/{1}", InnerDirectory, TextFileName)), Is.EqualTo(string.Format("/{0}/{1}/{2}/{3}", MediaFolder, ShellSettingsName, InnerDirectory, TextFileName)), "file within directory");
|
||||
Assert.That(MediaService.GetPublicUrl(TextFileName), Is.EqualTo(string.Format("/{0}/{1}/{2}", MediaFolder, ShellSettings.DefaultName, TextFileName)), "base path file");
|
||||
Assert.That(MediaService.GetPublicUrl(string.Format("{0}/{1}", InnerDirectory, TextFileName)), Is.EqualTo(string.Format("/{0}/{1}/{2}/{3}", MediaFolder, ShellSettings.DefaultName, InnerDirectory, TextFileName)), "file within directory");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace Orchard.Tests.Modules.Migrations {
|
||||
new Dictionary<string, object> {{"ProviderName", "SqlCe"}})
|
||||
});
|
||||
|
||||
builder.RegisterInstance(new ShellSettings { Name = "Default", DataTablePrefix = "TEST", DataProvider = "SqlCe" });
|
||||
builder.RegisterInstance(new ShellSettings { Name = ShellSettings.DefaultName, DataTablePrefix = "TEST", DataProvider = "SqlCe" });
|
||||
builder.RegisterInstance(AppDataFolderTests.CreateAppDataFolder(_tempFixtureFolderName)).As<IAppDataFolder>();
|
||||
builder.RegisterType<SessionConfigurationCache>().As<ISessionConfigurationCache>();
|
||||
builder.RegisterType<SqlCeDataServicesProvider>().As<IDataServicesProvider>();
|
||||
|
||||
@@ -143,6 +143,7 @@
|
||||
<Compile Include="Indexing\LuceneIndexProviderTests.cs" />
|
||||
<Compile Include="Indexing\LuceneSearchBuilderTests.cs" />
|
||||
<Compile Include="Media\Services\MediaServiceTests.cs" />
|
||||
<Compile Include="Packaging\Services\PackagingServicesTests.cs" />
|
||||
<Compile Include="Scripting.Dlr\EvaluatorTests.cs" />
|
||||
<Compile Include="Scripting\EvaluatorTestsBase.cs" />
|
||||
<Compile Include="Scripting\EvaluatorTests.cs" />
|
||||
@@ -151,9 +152,8 @@
|
||||
<Compile Include="Scripting\SimpleScriptingTests.cs" />
|
||||
<Compile Include="DatabaseEnabledTestsBase.cs" />
|
||||
<Compile Include="Media\Extensions\LongExtensionsTests.cs" />
|
||||
<EmbeddedResource Include="Packaging\HelloDriver.cs.txt" />
|
||||
<Compile Include="Packaging\PackageExpanderTests.cs" />
|
||||
<Compile Include="Packaging\PackageBuilderTests.cs" />
|
||||
<EmbeddedResource Include="Packaging\Services\HelloDriver.cs.txt" />
|
||||
<Compile Include="Packaging\Services\PackageBuilderTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Roles\Controllers\AdminControllerTests.cs" />
|
||||
<Compile Include="Roles\Services\RoleServiceTests.cs" />
|
||||
@@ -271,7 +271,7 @@
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Packaging\Hello.World.csproj.txt" />
|
||||
<EmbeddedResource Include="Packaging\Services\Hello.World.csproj.txt" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
using System.IO;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.FileSystems.VirtualPath;
|
||||
using Orchard.FileSystems.WebSite;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.Services;
|
||||
using Orchard.Tests.Stubs;
|
||||
|
||||
namespace Orchard.Tests.Modules.Packaging {
|
||||
[TestFixture]
|
||||
public class PackageExpanderTests : ContainerTestBase {
|
||||
protected override void Register(Autofac.ContainerBuilder builder) {
|
||||
builder.RegisterType<PackageBuilder>().As<IPackageBuilder>();
|
||||
builder.RegisterType<PackageInstaller>().As<IPackageInstaller>();
|
||||
builder.RegisterInstance<IVirtualPathProvider>(new StubVirtualPathProvider(new StubFileSystem(new Clock())));
|
||||
builder.RegisterType<InMemoryWebSiteFolder>().As<IWebSiteFolder>()
|
||||
.As<InMemoryWebSiteFolder>().InstancePerLifetimeScope();
|
||||
}
|
||||
|
||||
private Stream BuildHelloWorld(IPackageBuilder packageBuilder) {
|
||||
return packageBuilder.BuildPackage(new ExtensionDescriptor {
|
||||
ExtensionType = DefaultExtensionTypes.Module,
|
||||
Id = "Hello.World",
|
||||
Version = "1.0",
|
||||
Description = "a",
|
||||
Author = "b"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,6 @@
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Commands\GalleryCommands.cs" />
|
||||
<Compile Include="Commands\PackagingCommands.cs" />
|
||||
<Compile Include="Controllers\DownloadStreamResult.cs" />
|
||||
<Compile Include="Controllers\GalleryController.cs" />
|
||||
<Compile Include="DefaultPackagingUpdater.cs" />
|
||||
<Compile Include="ResourceManifest.cs" />
|
||||
@@ -8,12 +8,12 @@ using Orchard.FileSystems.WebSite;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.Tests.Stubs;
|
||||
|
||||
namespace Orchard.Tests.Modules.Packaging {
|
||||
namespace Orchard.Tests.Modules.Packaging.Services {
|
||||
[TestFixture]
|
||||
public class PackageBuilderTests : ContainerTestBase {
|
||||
private const string PackageIdentifier = "Hello.World";
|
||||
|
||||
protected override void Register(Autofac.ContainerBuilder builder) {
|
||||
protected override void Register(ContainerBuilder builder) {
|
||||
builder.RegisterType<PackageBuilder>().As<IPackageBuilder>();
|
||||
builder.RegisterType<InMemoryWebSiteFolder>().As<IWebSiteFolder>()
|
||||
.As<InMemoryWebSiteFolder>().InstancePerLifetimeScope();
|
||||
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using Autofac;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Caching;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Handlers;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.ContentManagement.MetaData.Models;
|
||||
using Orchard.ContentManagement.MetaData.Services;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Core.Settings.Handlers;
|
||||
using Orchard.Core.Settings.Metadata;
|
||||
using Orchard.Core.Settings.Models;
|
||||
using Orchard.Core.Settings.Services;
|
||||
using Orchard.Data;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.DisplayManagement.Descriptors;
|
||||
using Orchard.DisplayManagement.Implementation;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.Security;
|
||||
using Orchard.Security.Permissions;
|
||||
using Orchard.Security.Providers;
|
||||
using Orchard.Settings;
|
||||
using Orchard.Tests.Modules.Users;
|
||||
using Orchard.Tests.Stubs;
|
||||
using Orchard.UI.Notify;
|
||||
using Orchard.Users.Handlers;
|
||||
using Orchard.Users.Models;
|
||||
using Orchard.Users.Services;
|
||||
|
||||
namespace Orchard.Tests.Modules.Packaging.Services {
|
||||
public class PackagingServicesTests : DatabaseEnabledTestsBase {
|
||||
private Mock<IAuthorizer> _authorizer;
|
||||
private Mock<WorkContext> _workContext;
|
||||
private IUser _currentUser;
|
||||
|
||||
public override void Register(ContainerBuilder builder) {
|
||||
builder.RegisterType<SiteService>().As<ISiteService>();
|
||||
builder.RegisterType<DefaultContentManager>().As<IContentManager>();
|
||||
builder.RegisterType(typeof(SettingsFormatter))
|
||||
.As(typeof(IMapper<XElement, SettingsDictionary>))
|
||||
.As(typeof(IMapper<SettingsDictionary, XElement>));
|
||||
builder.RegisterType<ContentDefinitionManager>().As<IContentDefinitionManager>();
|
||||
builder.RegisterType<DefaultContentManagerSession>().As<IContentManagerSession>();
|
||||
builder.RegisterType<DefaultContentQuery>().As<IContentQuery>().InstancePerDependency();
|
||||
builder.RegisterType<MembershipService>().As<IMembershipService>();
|
||||
builder.RegisterType<UserService>().As<IUserService>();
|
||||
builder.RegisterType<UserPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<OrchardServices>().As<IOrchardServices>();
|
||||
builder.RegisterType<TransactionManager>().As<ITransactionManager>();
|
||||
builder.RegisterType<DefaultShapeTableManager>().As<IShapeTableManager>();
|
||||
builder.RegisterType<DefaultShapeFactory>().As<IShapeFactory>();
|
||||
builder.RegisterType<StubExtensionManager>().As<IExtensionManager>();
|
||||
builder.RegisterType<SiteSettingsPartHandler>().As<IContentHandler>();
|
||||
builder.RegisterType<PackagingServices>().As<IPackagingServices>();
|
||||
|
||||
builder.RegisterInstance(new Mock<INotifier>().Object);
|
||||
builder.RegisterInstance(new Mock<IContentDisplay>().Object);
|
||||
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
|
||||
builder.RegisterType<Signals>().As<ISignals>();
|
||||
|
||||
builder.RegisterType<DefaultEncryptionService>().As<IEncryptionService>();
|
||||
builder.RegisterInstance(ShellSettingsUtility.CreateEncryptionEnabled());
|
||||
|
||||
_authorizer = new Mock<IAuthorizer>();
|
||||
builder.RegisterInstance(_authorizer.Object);
|
||||
|
||||
_workContext = new Mock<WorkContext>();
|
||||
_workContext.Setup(w => w.GetState<ISite>(It.Is<string>(s => s == "CurrentSite"))).Returns(() => _container.Resolve<ISiteService>().GetSiteSettings());
|
||||
_workContext.Setup(w => w.GetState<IUser>(It.Is<string>(s => s == "CurrentUser"))).Returns(() => _currentUser);
|
||||
|
||||
var _workContextAccessor = new Mock<IWorkContextAccessor>();
|
||||
_workContextAccessor.Setup(w => w.GetContext()).Returns(_workContext.Object);
|
||||
builder.RegisterInstance(_workContextAccessor.Object).As<IWorkContextAccessor>();
|
||||
}
|
||||
|
||||
protected override IEnumerable<Type> DatabaseTypes {
|
||||
get {
|
||||
return new[] { typeof(UserPartRecord),
|
||||
typeof(SiteSettingsPartRecord),
|
||||
typeof(RegistrationSettingsPartRecord),
|
||||
typeof(ContentTypeRecord),
|
||||
typeof(ContentItemRecord),
|
||||
typeof(ContentItemVersionRecord),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CanManagePackagesTest() {
|
||||
const string superUsername = "admin";
|
||||
const string regularUsername = "user1";
|
||||
|
||||
IPackagingServices packagingServices = _container.Resolve<IPackagingServices>();
|
||||
IOrchardServices orchardServices = _container.Resolve<IOrchardServices>();
|
||||
ShellSettings shellSettings = _container.Resolve<ShellSettings>();
|
||||
shellSettings.Name = ShellSettings.DefaultName;
|
||||
|
||||
IUser regularUser = CreateUser(regularUsername);
|
||||
IUser superUser = CreateUser(superUsername);
|
||||
|
||||
orchardServices.WorkContext.CurrentSite.As<SiteSettingsPart>().SuperUser = superUsername;
|
||||
_currentUser = regularUser;
|
||||
_session.Flush();
|
||||
|
||||
// Setup authorizer to return false
|
||||
_authorizer.Setup(x => x.Authorize(It.IsAny<Permission>(), It.IsAny<LocalizedString>())).Returns(false);
|
||||
|
||||
// Test regular user without permission explicit assigned and which is not the default admin
|
||||
Assert.That(packagingServices.CanManagePackages(), Is.False);
|
||||
|
||||
// Test regular user with permission explicit assigned and which is not the default admin
|
||||
_authorizer.Setup(x => x.Authorize(It.IsAny<Permission>(), It.IsAny<LocalizedString>())).Returns(true);
|
||||
Assert.That(packagingServices.CanManagePackages(), Is.True);
|
||||
|
||||
// Test super user that even without permission explicit assigned should be able to manage packages
|
||||
_authorizer.Setup(x => x.Authorize(It.IsAny<Permission>(), It.IsAny<LocalizedString>())).Returns(false);
|
||||
Assert.That(packagingServices.CanManagePackages(), Is.False);
|
||||
_currentUser = superUser;
|
||||
Assert.That(packagingServices.CanManagePackages(), Is.True);
|
||||
|
||||
// Test with super user from another tenant site
|
||||
shellSettings.Name = "tenantsite2";
|
||||
_session.Flush();
|
||||
|
||||
Assert.That(packagingServices.CanManagePackages(), Is.False);
|
||||
}
|
||||
|
||||
private IUser CreateUser(string username) {
|
||||
var manager = _container.Resolve<IContentManager>();
|
||||
|
||||
UserPart userPart = manager.New<UserPart>("User");
|
||||
userPart.Record = new UserPartRecord { UserName = username, NormalizedUserName = username, Email = string.Format("{0}@orcharproject.com", username) };
|
||||
manager.Create(userPart.ContentItem);
|
||||
|
||||
return userPart;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ namespace Orchard.Tests.Modules.Settings.Blueprint {
|
||||
public string LastMessageName { get; set; }
|
||||
public IDictionary<string, object> LastEventData { get; set; }
|
||||
|
||||
public IEnumerable Notify(string messageName, IDictionary<string, object> eventData) {
|
||||
public IEnumerable Notify(string messageName, IDictionary<string, object> eventData) {
|
||||
LastMessageName = messageName;
|
||||
LastEventData = eventData;
|
||||
return new object[0];
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Linq;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Tests.Stubs;
|
||||
|
||||
@@ -23,7 +24,7 @@ namespace Orchard.Tests.Environment.Configuration {
|
||||
IShellSettingsManager loader = new ShellSettingsManager(_appDataFolder, new Mock<IShellSettingsManagerEventHandler>().Object);
|
||||
var settings = loader.LoadSettings().Single();
|
||||
Assert.That(settings, Is.Not.Null);
|
||||
Assert.That(settings.Name, Is.EqualTo("Default"));
|
||||
Assert.That(settings.Name, Is.EqualTo(ShellSettings.DefaultName));
|
||||
Assert.That(settings.DataProvider, Is.EqualTo("SqlCe"));
|
||||
Assert.That(settings.DataConnectionString, Is.EqualTo("something else"));
|
||||
}
|
||||
@@ -39,8 +40,8 @@ namespace Orchard.Tests.Environment.Configuration {
|
||||
var settings = loader.LoadSettings();
|
||||
Assert.That(settings.Count(), Is.EqualTo(2));
|
||||
|
||||
var def = settings.Single(x => x.Name == "Default");
|
||||
Assert.That(def.Name, Is.EqualTo("Default"));
|
||||
var def = settings.Single(x => x.Name == ShellSettings.DefaultName);
|
||||
Assert.That(def.Name, Is.EqualTo(ShellSettings.DefaultName));
|
||||
Assert.That(def.DataProvider, Is.EqualTo("SqlCe"));
|
||||
Assert.That(def.DataConnectionString, Is.EqualTo("something else"));
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using Autofac.Core;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Orchard.ContentManagement.Records;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
@@ -57,7 +58,7 @@ namespace Orchard.Tests.Environment {
|
||||
}
|
||||
|
||||
private static ShellSettings BuildDefaultSettings() {
|
||||
return new ShellSettings { Name = "Default" };
|
||||
return new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -294,4 +295,4 @@ namespace Orchard.Tests.Environment {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -122,7 +122,7 @@ namespace Orchard.Tests.Environment {
|
||||
}
|
||||
|
||||
public class StubShellSettingsLoader : IShellSettingsManager {
|
||||
private readonly List<ShellSettings> _shellSettings = new List<ShellSettings> { new ShellSettings { Name = "Default" } };
|
||||
private readonly List<ShellSettings> _shellSettings = new List<ShellSettings> { new ShellSettings { Name = ShellSettings.DefaultName } };
|
||||
|
||||
public IEnumerable<ShellSettings> LoadSettings() {
|
||||
return _shellSettings.AsEnumerable();
|
||||
@@ -240,7 +240,7 @@ namespace Orchard.Tests.Environment {
|
||||
public static ILifetimeScope CreateShellContainer_Obsolete(this IOrchardHost host) {
|
||||
return ((DefaultOrchardHost)host)
|
||||
.Current
|
||||
.Single(x => x.Settings.Name == "Default")
|
||||
.Single(x => x.Settings.Name == ShellSettings.DefaultName)
|
||||
.LifetimeScope;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void DefaultShellMatchesByDefault() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = "Default" };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
table.Add(settings);
|
||||
var match = table.Match(new StubHttpContext());
|
||||
Assert.That(match, Is.SameAs(settings));
|
||||
@@ -25,7 +25,7 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void AnotherShellMatchesByHostHeader() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = "Default" };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "a.example.com" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
@@ -36,7 +36,7 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void DefaultStillCatchesWhenOtherShellsMiss() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = "Default" };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "a.example.com" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
@@ -47,7 +47,7 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void DefaultWontFallbackIfItHasCriteria() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = "Default", RequestUrlHost = "www.example.com" };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName, RequestUrlHost = "www.example.com" };
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "a.example.com" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
@@ -58,7 +58,7 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void DefaultWillCatchRequestsIfItMatchesCriteria() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = "Default", RequestUrlHost = "www.example.com" };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName, RequestUrlHost = "www.example.com" };
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "a.example.com" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
@@ -69,7 +69,7 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void NonDefaultCatchallWillFallbackIfNothingElseMatches() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = "Default", RequestUrlHost = "www.example.com" };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName, RequestUrlHost = "www.example.com" };
|
||||
var settingsA = new ShellSettings { Name = "Alpha" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
@@ -80,7 +80,7 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void DefaultCatchallIsFallbackEvenWhenOthersAreUnqualified() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = "Default" };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
var settingsA = new ShellSettings { Name = "Alpha" };
|
||||
var settingsB = new ShellSettings { Name = "Beta", RequestUrlHost = "b.example.com" };
|
||||
var settingsG = new ShellSettings { Name = "Gamma" };
|
||||
@@ -95,7 +95,7 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void ThereIsNoFallbackIfMultipleSitesAreUnqualifiedButDefaultIsNotOneOfThem() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = "Default", RequestUrlHost = "www.example.com" };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName, RequestUrlHost = "www.example.com" };
|
||||
var settingsA = new ShellSettings { Name = "Alpha" };
|
||||
var settingsB = new ShellSettings { Name = "Beta", RequestUrlHost = "b.example.com" };
|
||||
var settingsG = new ShellSettings { Name = "Gamma" };
|
||||
@@ -110,7 +110,7 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void PathAlsoCausesMatch() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = "Default" };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlPrefix = "~/foo" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
@@ -121,7 +121,7 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void PathAndHostMustBothMatch() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = "Default", RequestUrlHost = "www.example.com", };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName, RequestUrlHost = "www.example.com", };
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "wiki.example.com", RequestUrlPrefix = "~/foo" };
|
||||
var settingsB = new ShellSettings { Name = "Beta", RequestUrlHost = "wiki.example.com", RequestUrlPrefix = "~/bar" };
|
||||
var settingsG = new ShellSettings { Name = "Gamma", RequestUrlHost = "wiki.example.com" };
|
||||
@@ -161,8 +161,8 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void HostNameMatchesRightmostIfRequestIsLonger() {
|
||||
var table = (IRunningShellTable) new RunningShellTable();
|
||||
var settings = new ShellSettings {Name = "Default"};
|
||||
var settingsA = new ShellSettings {Name = "Alpha", RequestUrlHost = "example.com"};
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "example.com" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "www.example.com")), Is.SameAs(settingsA));
|
||||
@@ -174,10 +174,10 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void LongestMatchingHostHasPriority() {
|
||||
var table = (IRunningShellTable) new RunningShellTable();
|
||||
var settings = new ShellSettings {Name = "Default"};
|
||||
var settingsA = new ShellSettings {Name = "Alpha", RequestUrlHost = "www.example.com"};
|
||||
var settingsB = new ShellSettings {Name = "Beta", RequestUrlHost = "example.com"};
|
||||
var settingsG = new ShellSettings {Name = "Gamma", RequestUrlHost = "wiki.example.com"};
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "www.example.com" };
|
||||
var settingsB = new ShellSettings { Name = "Beta", RequestUrlHost = "example.com" };
|
||||
var settingsG = new ShellSettings { Name = "Gamma", RequestUrlHost = "wiki.example.com" };
|
||||
table.Add(settings);
|
||||
table.Add(settingsA);
|
||||
table.Add(settingsB);
|
||||
@@ -193,7 +193,7 @@ namespace Orchard.Tests.Environment {
|
||||
[Test]
|
||||
public void ShellNameUsedToDistinctThingsAsTheyAreAdded() {
|
||||
var table = (IRunningShellTable)new RunningShellTable();
|
||||
var settings = new ShellSettings { Name = "Default" };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
var settingsA = new ShellSettings { Name = "Alpha", RequestUrlHost = "removed.example.com" };
|
||||
var settingsB = new ShellSettings { Name = "Alpha", RequestUrlHost = "added.example.com" };
|
||||
table.Add(settings);
|
||||
@@ -205,4 +205,4 @@ namespace Orchard.Tests.Environment {
|
||||
Assert.That(table.Match(new StubHttpContext("~/foo/bar", "localhost")), Is.SameAs(settings));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,7 @@ namespace Orchard.Tests.Environment.ShellBuilders {
|
||||
}
|
||||
|
||||
ShellSettings CreateSettings() {
|
||||
return new ShellSettings {Name = "Default"};
|
||||
return new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
}
|
||||
ShellBlueprint CreateBlueprint(params ShellBlueprintItem[] items) {
|
||||
return new ShellBlueprint {
|
||||
|
||||
@@ -28,13 +28,13 @@ namespace Orchard.Tests.Environment.ShellBuilders {
|
||||
|
||||
[Test]
|
||||
public void NormalExecutionReturnsExpectedObjects() {
|
||||
var settings = new ShellSettings { Name = "Default" };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName };
|
||||
var descriptor = new ShellDescriptor { SerialNumber = 6655321 };
|
||||
var blueprint = new ShellBlueprint();
|
||||
var shellLifetimeScope = _container.BeginLifetimeScope("shell");
|
||||
|
||||
_container.Mock<IShellDescriptorCache>()
|
||||
.Setup(x => x.Fetch("Default"))
|
||||
.Setup(x => x.Fetch(ShellSettings.DefaultName))
|
||||
.Returns(descriptor);
|
||||
|
||||
_container.Mock<ICompositionStrategy>()
|
||||
@@ -83,9 +83,9 @@ namespace Orchard.Tests.Environment.ShellBuilders {
|
||||
.Returns(_container.BeginLifetimeScope("shell"));
|
||||
|
||||
var factory = _container.Resolve<IShellContextFactory>();
|
||||
var context = factory.CreateSetupContext(new ShellSettings { Name = "Default" });
|
||||
var context = factory.CreateSetupContext(new ShellSettings { Name = ShellSettings.DefaultName });
|
||||
|
||||
Assert.That(context.Descriptor.Features, Has.Some.With.Property("Name").EqualTo("Orchard.Setup"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ namespace Orchard.Tests.Environment.State {
|
||||
public void CallingAddTaskReturnsResultIdentifierAndCausesPendingToBeTrue() {
|
||||
var engine = _container.Resolve<IProcessingEngine>();
|
||||
var pending1 = engine.AreTasksPending();
|
||||
var resultId = engine.AddTask(new ShellSettings {Name = "Default"}, null, null, null);
|
||||
var resultId = engine.AddTask(new ShellSettings { Name = ShellSettings.DefaultName }, null, null, null);
|
||||
var pending2 = engine.AreTasksPending();
|
||||
Assert.That(pending1, Is.False);
|
||||
Assert.That(resultId, Is.Not.Null);
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Mvc.Routes;
|
||||
using Orchard.Tests.Utility;
|
||||
@@ -27,7 +28,7 @@ namespace Orchard.Tests.Mvc {
|
||||
builder.RegisterType<RoutePublisher>().As<IRoutePublisher>();
|
||||
builder.RegisterType<ShellRoute>().InstancePerDependency();
|
||||
builder.Register(ctx => _routes);
|
||||
builder.Register(ctx => new ShellSettings { Name = "Default" });
|
||||
builder.Register(ctx => new ShellSettings { Name = ShellSettings.DefaultName });
|
||||
builder.RegisterAutoMocking();
|
||||
_container = builder.Build();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.FileSystems.Media;
|
||||
|
||||
@@ -12,7 +13,7 @@ namespace Orchard.Tests.Storage {
|
||||
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
_folderPath = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Media"), "Default");
|
||||
_folderPath = Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Media"), ShellSettings.DefaultName);
|
||||
_filePath = _folderPath + "\\testfile.txt";
|
||||
|
||||
if (Directory.Exists(_folderPath)) {
|
||||
@@ -30,7 +31,7 @@ namespace Orchard.Tests.Storage {
|
||||
var subsubfolder1 = Path.Combine(subfolder1, "SubSubfolder1");
|
||||
Directory.CreateDirectory(subsubfolder1);
|
||||
|
||||
_storageProvider = new FileSystemStorageProvider(new ShellSettings { Name = "Default" });
|
||||
_storageProvider = new FileSystemStorageProvider(new ShellSettings { Name = ShellSettings.DefaultName });
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Security;
|
||||
using Orchard.UI.Navigation;
|
||||
@@ -16,7 +17,7 @@ namespace Orchard.MultiTenancy {
|
||||
public string MenuName { get { return "admin"; } }
|
||||
|
||||
public void GetNavigation(NavigationBuilder builder) {
|
||||
if ( _shellSettings.Name != "Default" )
|
||||
if (_shellSettings.Name != ShellSettings.DefaultName)
|
||||
return;
|
||||
|
||||
builder.Add(T("Tenants"), "100",
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Localization;
|
||||
using Orchard.MultiTenancy.Services;
|
||||
@@ -158,7 +159,7 @@ namespace Orchard.MultiTenancy.Controllers {
|
||||
}
|
||||
|
||||
private bool EnsureDefaultTenant() {
|
||||
return _thisShellSettings.Name == "Default";
|
||||
return _thisShellSettings.Name == ShellSettings.DefaultName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,6 @@ namespace Orchard.Packaging.Commands {
|
||||
// Exceptions area thrown by NuGet as error messages
|
||||
throw new OrchardException(T(HttpUtility.HtmlDecode(T("Could not unintall the package: {0}", e.Message).Text)));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using System.IO;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Orchard.Packaging.Controllers {
|
||||
public class DownloadStreamResult : ActionResult {
|
||||
public string FileName { get; set; }
|
||||
public string ContentType { get; set; }
|
||||
public Stream Stream { get; set; }
|
||||
|
||||
public DownloadStreamResult(string fileName, string contentType, Stream stream) {
|
||||
FileName = fileName;
|
||||
ContentType = contentType;
|
||||
Stream = stream;
|
||||
}
|
||||
|
||||
public override void ExecuteResult(ControllerContext context) {
|
||||
context.HttpContext.Response.ContentType = ContentType;
|
||||
context.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=\"" + FileName + "\"");
|
||||
Stream.Seek(0, SeekOrigin.Begin);
|
||||
Stream.CopyTo(context.HttpContext.Response.OutputStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Services.Client;
|
||||
using System.Linq;
|
||||
using System.Web.Hosting;
|
||||
using System.Web.Mvc;
|
||||
@@ -12,7 +11,6 @@ using Orchard.Logging;
|
||||
using Orchard.Packaging.Models;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.Packaging.ViewModels;
|
||||
using Orchard.Security;
|
||||
using Orchard.Themes;
|
||||
using Orchard.UI.Admin;
|
||||
using Orchard.UI.Notify;
|
||||
@@ -23,15 +21,19 @@ namespace Orchard.Packaging.Controllers {
|
||||
[Themed, Admin]
|
||||
public class GalleryController : Controller {
|
||||
|
||||
private readonly IPackagingServices _packagingServices;
|
||||
private readonly IPackageManager _packageManager;
|
||||
private readonly IPackagingSourceManager _packagingSourceManager;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public GalleryController(
|
||||
IPackagingServices packagingServices,
|
||||
IPackageManager packageManager,
|
||||
IPackagingSourceManager packagingSourceManager,
|
||||
INotifier notifier,
|
||||
IOrchardServices services) {
|
||||
|
||||
_packagingServices = packagingServices;
|
||||
_packageManager = packageManager;
|
||||
_packagingSourceManager = packagingSourceManager;
|
||||
_notifier = notifier;
|
||||
@@ -46,7 +48,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public ActionResult Sources() {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to list sources")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
return View(new PackagingSourcesViewModel {
|
||||
@@ -55,7 +57,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
}
|
||||
|
||||
public ActionResult Remove(int id) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to remove sources")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
_packagingSourceManager.RemoveSource(id);
|
||||
@@ -64,7 +66,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
}
|
||||
|
||||
public ActionResult AddSource() {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to add sources")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
return View(new PackagingAddSourceViewModel());
|
||||
@@ -72,7 +74,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult AddSource(string url) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to add sources")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
@@ -126,7 +128,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
}
|
||||
|
||||
protected ActionResult ListExtensions(int? sourceId, string extensionType, string returnView, Func<PackagingSource, PackagingEntry[]> getList) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to list {0}", extensionType)))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var selectedSource = _packagingSourceManager.GetSources().Where(s => s.Id == sourceId).FirstOrDefault();
|
||||
@@ -156,7 +158,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
}
|
||||
|
||||
public ActionResult Install(string packageId, string version, int sourceId, string redirectTo) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to install packages")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
var source = _packagingSourceManager.GetSources().Where(s => s.Id == sourceId).FirstOrDefault();
|
||||
|
||||
@@ -10,7 +10,6 @@ using Orchard.FileSystems.AppData;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Mvc.Extensions;
|
||||
using Orchard.Packaging.Services;
|
||||
using Orchard.Security;
|
||||
using Orchard.Themes;
|
||||
using Orchard.UI.Admin;
|
||||
using Orchard.UI.Notify;
|
||||
@@ -22,15 +21,19 @@ namespace Orchard.Packaging.Controllers {
|
||||
[Themed, Admin]
|
||||
public class PackagingServicesController : Controller {
|
||||
|
||||
private readonly IPackagingServices _packagingServices;
|
||||
private readonly IPackageManager _packageManager;
|
||||
private readonly IAppDataFolderRoot _appDataFolderRoot;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public PackagingServicesController(
|
||||
IPackagingServices packagingServices,
|
||||
IPackageManager packageManager,
|
||||
INotifier notifier,
|
||||
IAppDataFolderRoot appDataFolderRoot,
|
||||
IOrchardServices services) {
|
||||
|
||||
_packagingServices = packagingServices;
|
||||
_packageManager = packageManager;
|
||||
_notifier = notifier;
|
||||
_appDataFolderRoot = appDataFolderRoot;
|
||||
@@ -43,7 +46,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
public IOrchardServices Services { get; set; }
|
||||
|
||||
public ActionResult AddTheme(string returnUrl) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to add themes")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
return View();
|
||||
@@ -51,7 +54,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
|
||||
[HttpPost, ActionName("AddTheme")]
|
||||
public ActionResult AddThemePOST(string returnUrl) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to add themes")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
return InstallPackage(returnUrl, Request.RawUrl);
|
||||
@@ -59,14 +62,14 @@ namespace Orchard.Packaging.Controllers {
|
||||
|
||||
[HttpPost, ActionName("RemoveTheme")]
|
||||
public ActionResult RemoveThemePOST(string themeId, string returnUrl, string retryUrl) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to remove themes")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
return UninstallPackage(PackageBuilder.BuildPackageId(themeId, DefaultExtensionTypes.Theme), returnUrl, retryUrl);
|
||||
}
|
||||
|
||||
public ActionResult AddModule(string returnUrl) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to add modules")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
return View();
|
||||
@@ -74,14 +77,14 @@ namespace Orchard.Packaging.Controllers {
|
||||
|
||||
[HttpPost, ActionName("AddModule")]
|
||||
public ActionResult AddModulePOST(string returnUrl) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to add modules")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
return InstallPackage(returnUrl, Request.RawUrl);
|
||||
}
|
||||
|
||||
public ActionResult InstallPackage(string returnUrl, string retryUrl) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to install packages")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
@@ -114,7 +117,7 @@ namespace Orchard.Packaging.Controllers {
|
||||
}
|
||||
|
||||
public ActionResult UninstallPackage(string id, string returnUrl, string retryUrl) {
|
||||
if (!Services.Authorizer.Authorize(StandardPermissions.SiteOwner, T("Not authorized to uninstall packages")))
|
||||
if (!_packagingServices.CanManagePackages())
|
||||
return new HttpUnauthorizedResult();
|
||||
|
||||
try {
|
||||
|
||||
@@ -61,23 +61,23 @@
|
||||
<Compile Include="AdminMenu.cs" />
|
||||
<Compile Include="Commands\PackagingCommands.cs" />
|
||||
<Compile Include="Controllers\PackagingServicesController.cs" />
|
||||
<Compile Include="Controllers\DownloadStreamResult.cs" />
|
||||
<Compile Include="Controllers\GalleryController.cs" />
|
||||
<Compile Include="DefaultPackagingUpdater.cs" />
|
||||
<Compile Include="Migrations.cs" />
|
||||
<Compile Include="Models\PackagingSource.cs" />
|
||||
<Compile Include="Permissions.cs" />
|
||||
<Compile Include="ResourceManifest.cs" />
|
||||
<Compile Include="Service References\GalleryServer\Reference.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Reference.datasvcmap</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Services\AtomExtensions.cs" />
|
||||
<Compile Include="Services\ExtensionReferenceRepository.cs" />
|
||||
<Compile Include="Services\FileBaseProjectSystem.cs" />
|
||||
<Compile Include="Services\IPackageBuilder.cs" />
|
||||
<Compile Include="Services\IPackageInstaller.cs" />
|
||||
<Compile Include="Services\IPackageManager.cs" />
|
||||
<Compile Include="Services\IPackagingServices.cs" />
|
||||
<Compile Include="Services\IPackagingSourceManager.cs" />
|
||||
<Compile Include="Services\NugetLogger.cs" />
|
||||
<Compile Include="Services\PackageBuilder.cs" />
|
||||
@@ -85,6 +85,7 @@
|
||||
<Compile Include="Services\PackageInstaller.cs" />
|
||||
<Compile Include="Services\PackageManager.cs" />
|
||||
<Compile Include="Services\PackagingEntry.cs" />
|
||||
<Compile Include="Services\PackagingServices.cs" />
|
||||
<Compile Include="Services\PackagingSourceManager.cs" />
|
||||
<Compile Include="ViewModels\PackagingAddSourceViewModel.cs" />
|
||||
<Compile Include="ViewModels\PackagingHarvestViewModel.cs" />
|
||||
|
||||
20
src/Orchard.Web/Modules/Orchard.Packaging/Permissions.cs
Normal file
20
src/Orchard.Web/Modules/Orchard.Packaging/Permissions.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Security.Permissions;
|
||||
|
||||
namespace Orchard.Packaging {
|
||||
public class Permissions : IPermissionProvider {
|
||||
public static readonly Permission ManagePackages = new Permission { Description = "Manage packages", Name = "ManagePackages" };
|
||||
|
||||
public virtual Feature Feature { get; set; }
|
||||
|
||||
public IEnumerable<Permission> GetPermissions() {
|
||||
return new[] { ManagePackages };
|
||||
}
|
||||
|
||||
public IEnumerable<PermissionStereotype> GetDefaultStereotypes() {
|
||||
// By default no one can manage packages except the default site administrator
|
||||
return new List<PermissionStereotype>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
using System.Xml.Linq;
|
||||
using Orchard.Environment.Extensions;
|
||||
|
||||
namespace Orchard.Packaging.Services {
|
||||
[OrchardFeature("PackagingServices")]
|
||||
internal static class AtomExtensions {
|
||||
public static string Atom(this XElement entry, string localName) {
|
||||
XElement element = entry.Element(AtomXName(localName));
|
||||
return element != null ? element.Value : null;
|
||||
}
|
||||
|
||||
public static XName AtomXName(string localName) {
|
||||
return XName.Get(localName, "http://www.w3.org/2005/Atom");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Orchard.Packaging.Services {
|
||||
/// <summary>
|
||||
/// Provides generic packaging related methods.
|
||||
/// </summary>
|
||||
public interface IPackagingServices : IDependency {
|
||||
|
||||
/// <summary>
|
||||
/// Verifies if the current user is allowed to manage packages. The super user of the default tenant site is always allowed.
|
||||
/// </summary>
|
||||
/// <returns>True if the allowed; false otherwise.</returns>
|
||||
bool CanManagePackages();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Hosting;
|
||||
using NuGet;
|
||||
using Orchard.Environment.Extensions;
|
||||
using Orchard.Environment.Extensions.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Packaging.Services {
|
||||
[OrchardFeature("PackagingServices")]
|
||||
@@ -13,17 +11,14 @@ namespace Orchard.Packaging.Services {
|
||||
private readonly IExtensionManager _extensionManager;
|
||||
private readonly IPackageBuilder _packageBuilder;
|
||||
private readonly IPackageInstaller _packageExpander;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public PackageManager(
|
||||
IExtensionManager extensionManager,
|
||||
IPackageBuilder packageBuilder,
|
||||
IPackageInstaller packageExpander,
|
||||
INotifier notifier) {
|
||||
IPackageInstaller packageExpander) {
|
||||
_extensionManager = extensionManager;
|
||||
_packageBuilder = packageBuilder;
|
||||
_packageExpander = packageExpander;
|
||||
_notifier = notifier;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using Orchard.Environment;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Localization;
|
||||
|
||||
namespace Orchard.Packaging.Services {
|
||||
/// <summary>
|
||||
/// Provides generic packaging related methods.
|
||||
/// </summary>
|
||||
public class PackagingServices : IPackagingServices {
|
||||
private readonly IOrchardServices _orchardServices;
|
||||
private readonly ShellSettings _shellSettings;
|
||||
|
||||
public PackagingServices(IOrchardServices orchardServices,
|
||||
ShellSettings shellSettings) {
|
||||
_orchardServices = orchardServices;
|
||||
_shellSettings = shellSettings;
|
||||
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Verifies if the current user is allowed to manage packages. The super user of the default tenant site is always allowed.
|
||||
/// </summary>
|
||||
/// <returns>True if the allowed; False otherwise.</returns>
|
||||
public bool CanManagePackages() {
|
||||
// Check if super user for default tenant site
|
||||
if (_shellSettings.Name == ShellSettings.DefaultName
|
||||
&& _orchardServices.WorkContext.CurrentUser.UserName == _orchardServices.WorkContext.CurrentSite.SuperUser) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if it has permission explicitly assigned
|
||||
return _orchardServices.Authorizer.Authorize(Permissions.ManagePackages, T("Not authorized to manage packages."));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Environment;
|
||||
using Orchard.FileSystems.AppData;
|
||||
using Orchard.Environment.Configuration;
|
||||
using Orchard.Setup.Services;
|
||||
using Orchard.Setup.ViewModels;
|
||||
using Orchard.Localization;
|
||||
@@ -11,13 +11,11 @@ using Orchard.UI.Notify;
|
||||
namespace Orchard.Setup.Controllers {
|
||||
[ValidateInput(false), Themed]
|
||||
public class SetupController : Controller {
|
||||
private readonly IAppDataFolder _appDataFolder;
|
||||
private readonly IViewsBackgroundCompilation _viewsBackgroundCompilation;
|
||||
private readonly INotifier _notifier;
|
||||
private readonly ISetupService _setupService;
|
||||
|
||||
public SetupController(INotifier notifier, ISetupService setupService, IAppDataFolder appDataFolder, IViewsBackgroundCompilation viewsBackgroundCompilation) {
|
||||
_appDataFolder = appDataFolder;
|
||||
public SetupController(INotifier notifier, ISetupService setupService, IViewsBackgroundCompilation viewsBackgroundCompilation) {
|
||||
_viewsBackgroundCompilation = viewsBackgroundCompilation;
|
||||
_notifier = notifier;
|
||||
_setupService = setupService;
|
||||
@@ -38,7 +36,7 @@ namespace Orchard.Setup.Controllers {
|
||||
// We use this opportunity to start a background task to "pre-compile" all the known
|
||||
// views in the app folder, so that the application is more reponsive when the user
|
||||
// hits the homepage and admin screens for the first time.
|
||||
if (StringComparer.OrdinalIgnoreCase.Equals(initialSettings.Name, "Default")) {
|
||||
if (StringComparer.OrdinalIgnoreCase.Equals(initialSettings.Name, ShellSettings.DefaultName)) {
|
||||
_viewsBackgroundCompilation.Start();
|
||||
}
|
||||
|
||||
@@ -98,4 +96,4 @@ namespace Orchard.Setup.Controllers {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ namespace Orchard.Commands {
|
||||
|
||||
public CommandReturnCodes RunCommand(TextReader input, TextWriter output, string tenant, string[] args, Dictionary<string, string> switches) {
|
||||
try {
|
||||
tenant = tenant ?? "Default";
|
||||
tenant = tenant ?? ShellSettings.DefaultName;
|
||||
|
||||
using (var env = CreateStandaloneEnvironment(tenant)) {
|
||||
var commandManager = env.Resolve<ICommandManager>();
|
||||
@@ -208,7 +208,7 @@ namespace Orchard.Commands {
|
||||
}
|
||||
else {
|
||||
// In case of an unitiliazed site (no default settings yet), we create a default settings instance.
|
||||
var settings = new ShellSettings { Name = "Default", State = new TenantState("Uninitialized") };
|
||||
var settings = new ShellSettings { Name = ShellSettings.DefaultName, State = new TenantState("Uninitialized") };
|
||||
return host.CreateStandaloneEnvironment(settings);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
/// from the App_Data settings.txt files.
|
||||
/// </summary>
|
||||
public class ShellSettings {
|
||||
public const string DefaultName = "Default";
|
||||
|
||||
public ShellSettings() {
|
||||
State = new TenantState("Invalid");
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace Orchard.Environment {
|
||||
|
||||
ShellContext CreateSetupContext() {
|
||||
Logger.Debug("Creating shell context for root setup");
|
||||
return _shellContextFactory.CreateSetupContext(new ShellSettings { Name = "Default" });
|
||||
return _shellContextFactory.CreateSetupContext(new ShellSettings { Name = ShellSettings.DefaultName });
|
||||
}
|
||||
|
||||
ShellContext CreateShellContext(ShellSettings settings) {
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Orchard.Environment {
|
||||
// two or more shells had no request criteria.
|
||||
// this is technically a misconfiguration - so fallback to the default shell
|
||||
// if it's one which will catch all requests
|
||||
_fallback = unqualified.SingleOrDefault(x => x.Name == "Default");
|
||||
_fallback = unqualified.SingleOrDefault(x => x.Name == ShellSettings.DefaultName);
|
||||
}
|
||||
else {
|
||||
// no shells are unqualified - a request that does not match a shell's spec
|
||||
|
||||
Reference in New Issue
Block a user