Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Validation for ProfileLink Uri #475

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
<PackageReference Update="Microsoft.AspNetCore.Session" Version="2.2.0" />
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="7.3.1" />
<PackageReference Update="Okta.AspNetCore" Version="4.5.0" />
<PackageReference Update="Mvp.Selections.Client" Version="4.13.1" />
<PackageReference Update="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Update="Mvp.Selections.Client" Version="4.14.0" />
<PackageReference Update="StyleCop.Analyzers" Version="1.2.0-beta.556" />
sc-ivanlieckens marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Update="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Update="Markdig" Version="0.34.0" />
<PackageReference Update="Markdig" Version="0.37.0" />
</ItemGroup>
</Project>
21 changes: 21 additions & 0 deletions src/Feature/Selections/rendering/Attributes/HttpsUrlAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.ComponentModel.DataAnnotations;

namespace Mvp.Feature.Selections.Attributes
{
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter)]
public class HttpsUrlAttribute()
: ValidationAttribute("The field {0} must be a Url starting with 'https'.")
{
public override bool IsValid(object value)
{
if (value == null)
{
return true;
}

return value is string valueAsString &&
valueAsString.StartsWith("https://", StringComparison.OrdinalIgnoreCase);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class ApplicationReviewSettingsModel : BaseModel

public TextField AddReviewerUserEmailLabel { get; set; }

public List<string> AddReviewerUserEmails { get; set; } = new ();
public List<string> AddReviewerUserEmails { get; set; } = [];

public Guid? RemoveReviewerUserId { get; set; }

Expand All @@ -45,6 +45,6 @@ public class ApplicationReviewSettingsModel : BaseModel

public Application Application { get; set; }

public List<User> Reviewers { get; set; } = new ();
public List<User> Reviewers { get; set; } = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public ApplicationsOverviewModel()

public TextField ReviewLinkFormat { get; set; }

public List<Country> Countries { get; set; } = new ();
public List<Country> Countries { get; set; } = [];

public List<Selection> Selections { get; set; } = new ();
public List<Selection> Selections { get; set; } = [];

public HyperLinkField ReviewSettingsLink { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions src/Feature/Selections/rendering/Models/Admin/AwardModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public class AwardModel : BaseModel

public Application Application { get; set; }

public List<ApplicationComment> Comments { get; set; } = new ();
public List<ApplicationComment> Comments { get; set; } = [];

public List<MvpType> MvpTypes { get; set; } = new ();
public List<MvpType> MvpTypes { get; set; } = [];

public short MvpTypeId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public class ScoreCardDetailModel : BaseModel

public Application Application { get; set; }

public List<Review> Reviews { get; set; } = new ();
public List<Review> Reviews { get; set; } = [];

public List<ScoreCategory> ScoreCategories { get; set; } = new ();
public List<ScoreCategory> ScoreCategories { get; set; } = [];

public List<Comment> Comments { get; set; } = new ();
public List<Comment> Comments { get; set; } = [];

public TextField TitleLabel { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ namespace Mvp.Feature.Selections.Models.Admin
{
public class ScoreCardsModel : BaseModel
{
public List<Selection> Selections { get; set; } = new ();
public List<Selection> Selections { get; set; } = [];

public Guid SelectedSelectionId { get; set; } = Guid.Empty;

public List<MvpType> MvpTypes { get; set; } = new ();
public List<MvpType> MvpTypes { get; set; } = [];

public short SelectedMvpTypeId { get; set; } = 0;

public List<ScoreCard> ScoreCards { get; set; } = new ();
public List<ScoreCard> ScoreCards { get; set; } = [];

public List<Title> Titles { get; set; } = new ();
public List<Title> Titles { get; set; } = [];

public TextField TitleLabel { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class UserEditModel : BaseModel
[Required]
public short CountryId { get; set; }

public List<Country> Countries { get; } = new ();
public List<Country> Countries { get; } = [];

public TextField SubmitLabel { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class MyDataEditModel : BaseModel
[FromForm(Name = $"{nameof(MyDataEditModel)}.{nameof(CountryId)}")]
public short CountryId { get; set; }

public List<Country> Countries { get; init; } = new ();
public List<Country> Countries { get; init; } = [];

public TextField ImageTypeLabel { get; set; }

Expand All @@ -43,7 +43,7 @@ public class MyDataEditModel : BaseModel

public Uri ImageUri { get; set; }

public List<Consent> Consents { get; init; } = new ();
public List<Consent> Consents { get; init; } = [];

public TextField SubmitLabel { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;
using Mvp.Feature.Selections.Attributes;
using Mvp.Selections.Domain;
using Sitecore.LayoutService.Client.Response.Model.Fields;

Expand All @@ -23,6 +24,7 @@ public class MyProfilesFormModel : BaseModel
public TextField LinkLabel { get; set; }

[Required]
[HttpsUrl]
[FromForm(Name = $"{nameof(MyProfilesFormModel)}.{nameof(Link)}")]
public Uri Link { get; set; }

Expand All @@ -34,7 +36,7 @@ public class MyProfilesFormModel : BaseModel

public TextField SubmitLabel { get; set; }

public List<ProfileLink> Links { get; init; } = new ();
public List<ProfileLink> Links { get; init; } = [];

public Guid? RemoveProfileLinkId { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ public class ApplicationFormModel : BaseModel

public TextField ContributionProductsLabel { get; set; }

public List<int> ContributionProductIds { get; set; } = new ();
public List<int> ContributionProductIds { get; set; } = [];

public TextField PublicContributionLabel { get; set; }

public bool ContributionIsPublic { get; set; } = false;

public List<Product> Products { get; } = new ();
public List<Product> Products { get; } = [];

public TextField AddLabel { get; set; }

Expand Down
2 changes: 1 addition & 1 deletion src/Feature/Selections/rendering/Models/BaseModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ public abstract class BaseModel
[SitecoreContextProperty]
public bool IsEditing { get; set; }

public List<string> ErrorMessages { get; set; } = new ();
public List<string> ErrorMessages { get; set; } = [];
}
}
2 changes: 1 addition & 1 deletion src/Feature/Selections/rendering/Models/ListModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class ListModel<T> : BaseModel
[FromQuery(Name = "ps")]
public short PageSize { get; set; } = 50;

public List<T> List { get; } = new ();
public List<T> List { get; } = [];

public BaseFilter Filter { get; set; } = new BaseFilter.None();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private async Task PostComment(ApplicationCommentModel model)
Response<User> getUserResponse = await Client.GetCurrentUserAsync();
if (getUserResponse.StatusCode == HttpStatusCode.OK && getUserResponse.Result != null)
{
ApplicationComment newComment = new (Guid.Empty)
ApplicationComment newComment = new(Guid.Empty)
{
Application = new Application(model.ApplicationId),
User = getUserResponse.Result,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@
namespace Mvp.Feature.Selections.ViewComponents.Admin
{
[ViewComponent(Name = ViewComponentName)]
public class ApplicationOverviewViewComponent : BaseViewComponent
public class ApplicationOverviewViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client)
: BaseViewComponent(modelBinder, client)
{
public const string ViewComponentName = "AdminApplicationsOverview";

public ApplicationOverviewViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client)
: base(modelBinder, client)
{
}

public override async Task<IViewComponentResult> InvokeAsync()
{
IViewComponentResult result;
Expand Down Expand Up @@ -118,7 +114,7 @@ private async Task LoadFilterValues(ApplicationsOverviewModel model)
{
Task<Response<IList<Country>>> countriesResponseTask = Client.GetCountriesAsync(1, short.MaxValue);
Task<Response<IList<Selection>>> selectionResponseTask = Client.GetSelectionsAsync(1, short.MaxValue);
List<Task> tasks = new () { countriesResponseTask, selectionResponseTask };
List<Task> tasks = [countriesResponseTask, selectionResponseTask];
while (tasks.Count > 0)
{
Task finished = await Task.WhenAny(tasks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
namespace Mvp.Feature.Selections.ViewComponents.Admin
{
[ViewComponent(Name = ViewComponentName)]
public class ApplicationReviewSettingsViewComponent : BaseViewComponent
public class ApplicationReviewSettingsViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client)
: BaseViewComponent(modelBinder, client)
{
public const string ViewComponentName = "AdminApplicationReviewSettings";

public ApplicationReviewSettingsViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client)
: base(modelBinder, client)
{
}

public override async Task<IViewComponentResult> InvokeAsync()
{
ApplicationReviewSettingsModel model = await ModelBinder.Bind<ApplicationReviewSettingsModel>(ViewContext);
Expand Down Expand Up @@ -75,7 +71,7 @@ private async Task LoadData(ApplicationReviewSettingsModel model)
{
Task<Response<IList<User>>> usersResponseTask = Client.GetUsersForApplicationReview(model.Id);
Task<Response<Application>> applicationResponseTask = Client.GetApplicationAsync(model.Id);
List<Task> tasks = new () { usersResponseTask, applicationResponseTask };
List<Task> tasks = [usersResponseTask, applicationResponseTask];
while (tasks.Count > 0)
{
Task finished = await Task.WhenAny(tasks);
Expand Down Expand Up @@ -114,7 +110,7 @@ private async Task LoadData(ApplicationReviewSettingsModel model)

private async Task AddReviewers(ApplicationReviewSettingsModel model)
{
Dictionary<Task<Response<IList<User>>>, string> tasks = new (model.AddReviewerUserEmails.Count);
Dictionary<Task<Response<IList<User>>>, string> tasks = new(model.AddReviewerUserEmails.Count);
foreach (string email in model.AddReviewerUserEmails)
{
tasks.Add(Client.GetUsersAsync(email: email), email);
Expand Down Expand Up @@ -187,7 +183,7 @@ private async Task RemoveReviewer(ApplicationReviewSettingsModel model)
Response<IList<SelectionRole>> selectionRolesResponse = await Client.GetSelectionRolesAsync(applicationId: model.Id);
if (selectionRolesResponse.StatusCode == HttpStatusCode.OK && selectionRolesResponse.Result != null)
{
List<Task> removeTasks = new (selectionRolesResponse.Result.Count);
List<Task> removeTasks = new(selectionRolesResponse.Result.Count);
foreach (SelectionRole role in selectionRolesResponse.Result)
{
removeTasks.Add(Client.RemoveUserFromRoleAsync(role.Id, model.RemoveReviewerUserId!.Value));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ await Task.WhenAll(

private static void GenerateFakeDataForEdit(AwardModel model)
{
MvpType loremMvp = new (1)
MvpType loremMvp = new(1)
{
Name = "Lorem"
};

MvpType ipsumMvp = new (2)
MvpType ipsumMvp = new(2)
{
Name = "Ipsum"
};

Application dolorApplication = new (Guid.NewGuid())
Application dolorApplication = new(Guid.NewGuid())
{
Applicant = new User(Guid.NewGuid())
{
Expand All @@ -92,7 +92,7 @@ private static void GenerateFakeDataForEdit(AwardModel model)
Status = ApplicationStatus.Submitted
};

model.Title = new (Guid.NewGuid())
model.Title = new(Guid.NewGuid())
{
Warning = "Donec varius, leo eget iaculis placerat, sapien orci iaculis nulla, ut facilisis eros arcu a ex.",
MvpType = loremMvp,
Expand Down Expand Up @@ -138,7 +138,7 @@ private static void GenerateFakeDataForEdit(AwardModel model)

private async Task AwardTitle(AwardModel model)
{
Title newTitle = new (Guid.Empty)
Title newTitle = new(Guid.Empty)
{
MvpType = model.MvpTypes.Single(t => t.Id == model.MvpTypeId),
Application = model.Application,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
namespace Mvp.Feature.Selections.ViewComponents.Admin
{
[ViewComponent(Name = ViewComponentName)]
public class RegionsOverviewViewComponent : BaseViewComponent
public class RegionsOverviewViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client)
: BaseViewComponent(modelBinder, client)
{
public const string ViewComponentName = "AdminRegionsOverview";

public RegionsOverviewViewComponent(IViewModelBinder modelBinder, MvpSelectionsApiClient client)
: base(modelBinder, client)
{
}

public override async Task<IViewComponentResult> InvokeAsync()
{
RegionsOverviewModel model = await ModelBinder.Bind<RegionsOverviewModel>(ViewContext);
Expand All @@ -41,7 +37,7 @@ public override async Task<IViewComponentResult> InvokeAsync()

private static void GenerateFakeDataForEdit(RegionsOverviewModel model)
{
Region region = new (1)
Region region = new(1)
{
Name = "Lorem"
};
Expand Down
Loading
Loading