Skip to content

Commit

Permalink
Fix multiple suggestions (#15204)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Jan 30, 2024
1 parent 2905658 commit 197b68d
Show file tree
Hide file tree
Showing 89 changed files with 213 additions and 226 deletions.
23 changes: 10 additions & 13 deletions src/OrchardCore.Modules/OrchardCore.Admin/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Permissions : IPermissionProvider

public Task<IEnumerable<Permission>> GetPermissionsAsync()
{
return Task.FromResult(GetPermissions());
return Task.FromResult(_permissions);
}

public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
Expand All @@ -20,37 +20,34 @@ public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
new PermissionStereotype
{
Name = "Administrator",
Permissions = GetPermissions(),
Permissions = _permissions,
},
new PermissionStereotype
{
Name = "Editor",
Permissions = GetPermissions(),
Permissions = _permissions,
},
new PermissionStereotype
{
Name = "Moderator",
Permissions = GetPermissions(),
Permissions = _permissions,
},
new PermissionStereotype
{
Name = "Author",
Permissions = GetPermissions(),
Permissions = _permissions,
},
new PermissionStereotype
{
Name = "Contributor",
Permissions = GetPermissions(),
Permissions = _permissions,
}
};
}

private static IEnumerable<Permission> GetPermissions()
{
return new[]
{
AccessAdminPanel,
};
}
private readonly IEnumerable<Permission> _permissions =
[
AccessAdminPanel
];
}
}
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Alias/Migrations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task<int> UpdateFrom2Async()
{
// Can't be fully created on existing databases where the 'Alias' may be of 767 chars.
await SchemaBuilder.AlterIndexTableAsync<AliasPartIndex>(table => table
//.CreateIndex("IDX_AliasPartIndex_DocumentId",
// .CreateIndex("IDX_AliasPartIndex_DocumentId",
// "DocumentId",
// "Alias",
// "ContentItemId",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public async Task<string> GetContentItemIdAsync(string handle)
internal class AliasPartContentHandleHelper
{
internal static Task<ContentItem> QueryAliasIndex(ISession session, string alias) =>
session.Query<ContentItem, AliasPartIndex>(x => x.Alias == alias.ToLowerInvariant()).FirstOrDefaultAsync();
session.Query<ContentItem, AliasPartIndex>(x => x.Alias.Equals(alias, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefaultAsync();
}
}
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Alias/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override void ConfigureServices(IServiceCollection services)
var session = context.Services.GetRequiredService<ISession>();
var contentItem = await session.Query<ContentItem, AliasPartIndex>(x =>
x.Published && x.Alias == alias.ToLowerInvariant())
x.Published && x.Alias.Equals(alias, System.StringComparison.InvariantCultureIgnoreCase))
.FirstOrDefaultAsync();
if (contentItem == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace OrchardCore.Apis.GraphQL
{
public class OrchardFieldNameConverter : INameConverter
{
private readonly INameConverter _defaultConverter = new CamelCaseNameConverter();
private readonly CamelCaseNameConverter _defaultConverter = new();

// todo: custom argument name?
public string NameForArgument(string argumentName, IComplexGraphType parentGraphType, FieldType field)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class AutoSetupOptions : IValidatableObject
/// <returns>The collection of errors.</returns>
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
if (!string.IsNullOrWhiteSpace(AutoSetupPath) && !AutoSetupPath.StartsWith("/"))
if (!string.IsNullOrWhiteSpace(AutoSetupPath) && !AutoSetupPath.StartsWith('/'))
{
yield return new ValidationResult($"The field '{nameof(AutoSetupPath)}' should be empty or start with '/'.");
}
Expand Down
12 changes: 2 additions & 10 deletions src/OrchardCore.Modules/OrchardCore.Autoroute/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Permissions : IPermissionProvider
public static readonly Permission SetHomepage = new("SetHomepage", "Set homepage.");
public Task<IEnumerable<Permission>> GetPermissionsAsync()
{
return Task.FromResult(GetPermissions());
return Task.FromResult<IEnumerable<Permission>>([SetHomepage]);
}

public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
Expand All @@ -19,17 +19,9 @@ public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
new PermissionStereotype
{
Name = "Administrator",
Permissions = GetPermissions(),
Permissions = [SetHomepage],
},
};
}

private static IEnumerable<Permission> GetPermissions()
{
return new[]
{
SetHomepage,
};
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Permissions : IPermissionProvider

public Task<IEnumerable<Permission>> GetPermissionsAsync()
{
return Task.FromResult(GetPermissions());
return Task.FromResult<IEnumerable<Permission>>([ManageBackgroundTasks]);
}

public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
Expand All @@ -20,14 +20,9 @@ public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
new PermissionStereotype
{
Name = "Administrator",
Permissions = new[] { ManageBackgroundTasks },
Permissions = [ManageBackgroundTasks],
}
};
}

private static IEnumerable<Permission> GetPermissions()
{
return new[] { ManageBackgroundTasks };
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task<IActionResult> SearchLocalizationSets(string part, string fiel
{
results.Add(new VueMultiselectItemViewModel
{
Id = contentItem.Key, //localization set
Id = contentItem.Key, // localization set
DisplayText = contentItem.Value.ToString(),
HasPublished = await _contentManager.HasPublishedVersionAsync(contentItem.Value)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public override IDisplayResult Edit(LocalizationSetContentPickerField field, Bui
model.SelectedItems.Add(new VueMultiselectItemViewModel
{
Id = kvp.Key, //localization set
Id = kvp.Key, // localization set
DisplayText = contentItem.ToString(),
HasPublished = await _contentManager.HasPublishedVersionAsync(contentItem)
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ public class ContentFieldsProvider : IContentFieldProvider

public FieldType GetField(ContentPartFieldDefinition field)
{
if (!_contentFieldTypeMappings.ContainsKey(field.FieldDefinition.Name))
if (!_contentFieldTypeMappings.TryGetValue(field.FieldDefinition.Name, out var value))
{
return null;
}

var fieldDescriptor = _contentFieldTypeMappings[field.FieldDefinition.Name];
var fieldDescriptor = value;
return new FieldType
{
Name = field.Name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ public async Task<IDictionary<string, string>> GetFirstItemIdForSetsAsync(IEnume
/// OR null if nothing found.
/// </summary>
/// <returns>List of ContentItemId.</returns>
private static IEnumerable<LocalizedContentItemIndex> GetSingleContentItemIdPerSet(IEnumerable<LocalizedContentItemIndex> indexValues, string currentCulture, string defaultCulture)
private static List<LocalizedContentItemIndex> GetSingleContentItemIdPerSet(IEnumerable<LocalizedContentItemIndex> indexValues, string currentCulture, string defaultCulture)
{
return indexValues.GroupBy(l => l.LocalizationSet).Select(set =>
{
var currentcultureContentItem = set.FirstOrDefault(f => f.Culture == currentCulture);
if (currentcultureContentItem is not null)
var currentCultureContentItem = set.FirstOrDefault(f => f.Culture == currentCulture);
if (currentCultureContentItem is not null)
{
return currentcultureContentItem;
return currentCultureContentItem;
}
var defaultCultureContentItem = set.FirstOrDefault(f => f.Culture == defaultCulture);
Expand Down
17 changes: 7 additions & 10 deletions src/OrchardCore.Modules/OrchardCore.ContentTypes/Permissions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Permissions : IPermissionProvider

public Task<IEnumerable<Permission>> GetPermissionsAsync()
{
return Task.FromResult(GetPermissions());
return Task.FromResult(_permissions);
}

public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
Expand All @@ -21,18 +21,15 @@ public IEnumerable<PermissionStereotype> GetDefaultStereotypes()
new PermissionStereotype
{
Name = "Administrator",
Permissions = GetPermissions(),
Permissions = _permissions,
},
};
}

private static IEnumerable<Permission> GetPermissions()
{
return new[]
{
ViewContentTypes,
EditContentTypes,
};
}
private readonly IEnumerable<Permission> _permissions =
[
ViewContentTypes,
EditContentTypes,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public class ContentItemRecursionHelper<T> : IContentItemRecursionHelper<T>
/// <inheritdocs />
public bool IsRecursive(ContentItem contentItem, int maxRecursions = 1)
{
if (_recursions.ContainsKey(contentItem))
if (_recursions.TryGetValue(contentItem, out var counter))
{
var counter = _recursions[contentItem];
if (maxRecursions < 1)
{
maxRecursions = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
//using OrchardCore.ContentManagement;
// using OrchardCore.ContentManagement;

//namespace OrchardCore.Contents.ViewModels
//{
// namespace OrchardCore.Contents.ViewModels
// {
// public class PublishContentViewModel
// {
// public PublishContentViewModel(ContentItem contentItem)
// {
// ContentItem = contentItem;
// }

// public ContentItem ContentItem { get; private set; }
// public ContentItem ContentItem { get; private set; }
// public bool HasDraft { get; }
// public bool HasPublished { get; }

// //ContentItem.ContentManager.Get(ContentItem.Id, VersionOptions.Published) != null;
// //ContentItem.ContentManager.Get(ContentItem.Id, VersionOptions.Published) != null;
// }
//}
// }
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Demo/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public override void ConfigureServices(IServiceCollection services)
options.Conventions.AddAreaPageRoute("OrchardCore.Demo", "/Hello", "Hello");
// This declaration would define an home page
//options.Conventions.AddAreaPageRoute("OrchardCore.Demo", "/Hello", "");
// options.Conventions.AddAreaPageRoute("OrchardCore.Demo", "/Hello", "");
});

services.AddTagHelpers(typeof(BazTagHelper).Assembly);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ namespace OrchardCore.Demo.TagHelpers
[HtmlTargetElement("baz")]
public class BazTagHelper : BaseShapeTagHelper
{
public BazTagHelper(IShapeFactory shapeFactory, IDisplayHelper displayHelper) :
base(shapeFactory, displayHelper)
public BazTagHelper(IShapeFactory shapeFactory, IDisplayHelper displayHelper)
: base(shapeFactory, displayHelper)
{
Type = "Baz";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public async Task<ActionResult> IndexPost(ViewModels.ContentOptions options, IEn
await _notifier.SuccessAsync(H["Remote clients successfully removed."]);
break;
default:
throw new ArgumentOutOfRangeException(nameof(options.BulkAction), "Invalid bulk action.");
return BadRequest();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public async Task<ActionResult> IndexPost(ViewModels.ContentOptions options, IEn
await _notifier.SuccessAsync(H["Remote instances successfully removed."]);
break;
default:
throw new ArgumentOutOfRangeException(nameof(options.BulkAction), "Invalid bulk action.");
return BadRequest();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder ro
defaults: new { controller = remoteInstanceControllerName, action = nameof(RemoteInstanceController.Edit) }
);

//ExportRemoteInstance
// ExportRemoteInstance
routes.MapAreaControllerRoute(
name: "DeploymentExportRemoteInstanceExecute",
areaName: "OrchardCore.Deployment.Remote",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task<IEnumerable<DeploymentPlan>> GetDeploymentPlansAsync(params st
return GetDeploymentPlans(deploymentPlans, deploymentPlanNames);
}

private static IEnumerable<DeploymentPlan> GetDeploymentPlans(IDictionary<string, DeploymentPlan> deploymentPlans, params string[] deploymentPlanNames)
private static IEnumerable<DeploymentPlan> GetDeploymentPlans(Dictionary<string, DeploymentPlan> deploymentPlans, params string[] deploymentPlanNames)
{
foreach (var deploymentPlanName in deploymentPlanNames)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,34 @@ public async Task DisableFeaturesAsync(IEnumerable<string> featureIds, bool forc
///// Determines if a module was recently installed by using the project's last written time.
///// </summary>
///// <param name="extensionDescriptor">The extension descriptor.</param>
//public bool IsRecentlyInstalled(ExtensionDescriptor extensionDescriptor) {
// public bool IsRecentlyInstalled(ExtensionDescriptor extensionDescriptor) {
// DateTime lastWrittenUtc = _cacheManager.Get(extensionDescriptor, descriptor => {
// string projectFile = GetManifestPath(extensionDescriptor);
// if (!string.IsNullOrEmpty(projectFile)) {
// // If project file was modified less than 24 hours ago, the module was recently deployed
// return _virtualPathProvider.GetFileLastWriteTimeUtc(projectFile);
// }

// return DateTime.UtcNow;
// return DateTime.UtcNow;
// });

// return DateTime.UtcNow.Subtract(lastWrittenUtc) < new TimeSpan(1, 0, 0, 0);
//}
// return DateTime.UtcNow.Subtract(lastWrittenUtc) < new TimeSpan(1, 0, 0, 0);
// }

///// <summary>
///// Retrieves the full path of the manifest file for a module's extension descriptor.
///// </summary>
///// <param name="extensionDescriptor">The module's extension descriptor.</param>
///// <returns>The full path to the module's manifest file.</returns>
//private string GetManifestPath(ExtensionDescriptor extensionDescriptor) {
// private string GetManifestPath(ExtensionDescriptor extensionDescriptor) {
// string projectPath = _virtualPathProvider.Combine(extensionDescriptor.Location, extensionDescriptor.Id, "module.txt");

// if (!_virtualPathProvider.FileExists(projectPath)) {
// if (!_virtualPathProvider.FileExists(projectPath)) {
// return null;
// }

// return projectPath;
//}
// return projectPath;
// }

private static ModuleFeature AssembleModuleFromDescriptor(IFeatureInfo featureInfo, bool isEnabled)
{
Expand All @@ -141,11 +141,11 @@ private static ModuleFeature AssembleModuleFromDescriptor(IFeatureInfo featureIn
};
}

//private void GenerateWarning(string messageFormat, string featureName, IEnumerable<string> featuresInQuestion) {
// private void GenerateWarning(string messageFormat, string featureName, IEnumerable<string> featuresInQuestion) {
// if (featuresInQuestion.Count() < 1)
// return;

// Services.Notifier.Warning(T(
// Services.Notifier.Warning(T(
// messageFormat,
// featureName,
// featuresInQuestion.Count() > 1
Expand All @@ -158,6 +158,6 @@ private static ModuleFeature AssembleModuleFromDescriptor(IFeatureInfo featureIn
// ? "{0} and "
// : "{0}, "), fn).ToString()).ToArray())
// : featuresInQuestion.First()));
//}
// }
}
}
Loading

0 comments on commit 197b68d

Please sign in to comment.