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

Introduce DynamicJavaScriptProxyOptions #10370

Merged
merged 7 commits into from
Oct 25, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Volo.Abp.Cli.ServiceProxying.JavaScript;
using Volo.Abp.Domain;
using Volo.Abp.Http;
using Volo.Abp.Http.ProxyScripting.Generators.JQuery;
using Volo.Abp.IdentityModel;
using Volo.Abp.Json;
using Volo.Abp.Json.SystemTextJson;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;

namespace Volo.Abp.Http.ProxyScripting.Generators.JQuery
{
public class DynamicJavaScriptProxyOptions
{
public HashSet<string> DisabledModules { get; }

public DynamicJavaScriptProxyOptions()
{
DisabledModules = new HashSet<string>();
}

public void DisableModule(string module)
{
DisabledModules.AddIfNotContains(module);
}

public void EnableModule(string module)
{
DisabledModules.Remove(module);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Extensions.Options;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Http.Modeling;

Expand All @@ -19,24 +20,46 @@ public class JQueryProxyScriptGenerator : IProxyScriptGenerator, ITransientDepen
/// </summary>
public const string Name = "jquery";

private readonly DynamicJavaScriptProxyOptions _dynamicJavaScriptProxyOptions;

public JQueryProxyScriptGenerator(IOptions<DynamicJavaScriptProxyOptions> dynamicJavaScriptProxyOptions)
{
_dynamicJavaScriptProxyOptions = dynamicJavaScriptProxyOptions.Value;
}

public string CreateScript(ApplicationApiDescriptionModel model)
{
var script = new StringBuilder();

script.AppendLine("/* This file is automatically generated by ABP framework to use MVC Controllers from javascript. */");
script.AppendLine();

foreach (var module in model.Modules.Values)
foreach (var module in model.Modules)
{
if (!ShouldCreateModuleScript(module))
{
continue;
}

script.AppendLine();
AddModuleScript(script, module);
AddModuleScript(script, module.Value);
}

AddInitializedEventTrigger(script);

return script.ToString();
}

private bool ShouldCreateModuleScript(KeyValuePair<string, ModuleApiDescriptionModel> module)
{
if (_dynamicJavaScriptProxyOptions.DisabledModules.Contains(module.Key))
{
return false;
}

return true;
}

private static void AddModuleScript(StringBuilder script, ModuleApiDescriptionModel module)
{
//TODO: Eleminate repeating module.RootPath.Replace("/", ".").ToCamelCase() !
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@
public static class AccountRemoteServiceConsts
{
public const string RemoteServiceName = "AbpAccount";

public const string ModuleName = "account";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Auditing;
using Volo.Abp.Identity;
using Volo.Abp.Validation;

namespace Volo.Abp.Identity
namespace Volo.Abp.Account
{
public class ChangePasswordInput
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Identity;

namespace Volo.Abp.Identity
namespace Volo.Abp.Account
{
public interface IProfileAppService : IApplicationService
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Volo.Abp.Domain.Entities;
using Volo.Abp.ObjectExtending;

namespace Volo.Abp.Identity
namespace Volo.Abp.Account
{
public class ProfileDto : ExtensibleObject, IHasConcurrencyStamp
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.ComponentModel.DataAnnotations;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Identity;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Validation;

namespace Volo.Abp.Identity
namespace Volo.Abp.Account
{
public class UpdateProfileDto : ExtensibleObject
{
Expand All @@ -24,4 +23,4 @@ public class UpdateProfileDto : ExtensibleObject

public string ConcurrencyStamp { get; set; }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Volo.Abp.Emailing;
using Volo.Abp.AutoMapper;
using Volo.Abp.Emailing;
using Volo.Abp.Identity;
using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation;
Expand All @@ -22,6 +23,11 @@ public override void ConfigureServices(ServiceConfigurationContext context)
options.FileSets.AddEmbedded<AbpAccountApplicationModule>();
});

Configure<AbpAutoMapperOptions>(options =>
{
options.AddProfile<AbpAccountApplicationModuleAutoMapperProfile>(validate: true);
});

Configure<AppUrlOptions>(options =>
{
options.Applications["MVC"].Urls[AccountUrlNames.PasswordReset] = "Account/ResetPassword";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using AutoMapper;
using Volo.Abp.Identity;

namespace Volo.Abp.Account
{
public class AbpAccountApplicationModuleAutoMapperProfile : Profile
{
public AbpAccountApplicationModuleAutoMapperProfile()
{
CreateMap<IdentityUser, ProfileDto>()
.ForMember(dest => dest.HasPassword,
op => op.MapFrom(src => src.PasswordHash != null))
.MapExtraProperties();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
using Volo.Abp.Data;
using Volo.Abp.Identity;
using Volo.Abp.Identity.Settings;
using Volo.Abp.Settings;
using Volo.Abp.ObjectExtending;
using Volo.Abp.Settings;
using Volo.Abp.Users;

namespace Volo.Abp.Identity
namespace Volo.Abp.Account
{
[Authorize]
public class ProfileAppService : IdentityAppServiceBase, IProfileAppService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Volo.Abp.Identity;

// ReSharper disable once CheckNamespace
namespace Volo.Abp.Identity.ClientProxies
namespace Volo.Abp.Account.ClientProxies
{
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IProfileAppService), typeof(ProfileClientProxy))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of ProfileClientProxy, you can customize it here
// ReSharper disable once CheckNamespace
namespace Volo.Abp.Identity.ClientProxies
namespace Volo.Abp.Account.ClientProxies
{
public partial class ProfileClientProxy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,110 @@
"implementFrom": "Volo.Abp.Account.Web.Areas.Account.Controllers.AccountController"
}
}
},
"Volo.Abp.Account.ProfileController": {
"controllerName": "Profile",
"controllerGroupName": "Profile",
"type": "Volo.Abp.Account.ProfileController",
"interfaces": [
{
"type": "Volo.Abp.Account.IProfileAppService"
}
],
"actions": {
"GetAsync": {
"uniqueName": "GetAsync",
"name": "GetAsync",
"httpMethod": "GET",
"url": "api/account/my-profile",
"supportedVersions": [],
"parametersOnMethod": [],
"parameters": [],
"returnValue": {
"type": "Volo.Abp.Account.ProfileDto",
"typeSimple": "Volo.Abp.Account.ProfileDto"
},
"allowAnonymous": null,
"implementFrom": "Volo.Abp.Account.IProfileAppService"
},
"UpdateAsyncByInput": {
"uniqueName": "UpdateAsyncByInput",
"name": "UpdateAsync",
"httpMethod": "PUT",
"url": "api/account/my-profile",
"supportedVersions": [],
"parametersOnMethod": [
{
"name": "input",
"typeAsString": "Volo.Abp.Account.UpdateProfileDto, Volo.Abp.Account.Application.Contracts",
"type": "Volo.Abp.Account.UpdateProfileDto",
"typeSimple": "Volo.Abp.Account.UpdateProfileDto",
"isOptional": false,
"defaultValue": null
}
],
"parameters": [
{
"nameOnMethod": "input",
"name": "input",
"jsonName": null,
"type": "Volo.Abp.Account.UpdateProfileDto",
"typeSimple": "Volo.Abp.Account.UpdateProfileDto",
"isOptional": false,
"defaultValue": null,
"constraintTypes": null,
"bindingSourceId": "Body",
"descriptorName": ""
}
],
"returnValue": {
"type": "Volo.Abp.Account.ProfileDto",
"typeSimple": "Volo.Abp.Account.ProfileDto"
},
"allowAnonymous": null,
"implementFrom": "Volo.Abp.Account.IProfileAppService"
},
"ChangePasswordAsyncByInput": {
"uniqueName": "ChangePasswordAsyncByInput",
"name": "ChangePasswordAsync",
"httpMethod": "POST",
"url": "api/account/my-profile/change-password",
"supportedVersions": [],
"parametersOnMethod": [
{
"name": "input",
"typeAsString": "Volo.Abp.Account.ChangePasswordInput, Volo.Abp.Account.Application.Contracts",
"type": "Volo.Abp.Account.ChangePasswordInput",
"typeSimple": "Volo.Abp.Account.ChangePasswordInput",
"isOptional": false,
"defaultValue": null
}
],
"parameters": [
{
"nameOnMethod": "input",
"name": "input",
"jsonName": null,
"type": "Volo.Abp.Account.ChangePasswordInput",
"typeSimple": "Volo.Abp.Account.ChangePasswordInput",
"isOptional": false,
"defaultValue": null,
"constraintTypes": null,
"bindingSourceId": "Body",
"descriptorName": ""
}
],
"returnValue": {
"type": "System.Void",
"typeSimple": "System.Void"
},
"allowAnonymous": null,
"implementFrom": "Volo.Abp.Account.IProfileAppService"
}
}
}
}
}
},
"types": {}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Volo.Abp.Account
{
[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)]
[Area("account")]
[Area(AccountRemoteServiceConsts.ModuleName)]
[Route("api/account")]
public class AccountController : AbpControllerBase, IAccountAppService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;

namespace Volo.Abp.Identity
namespace Volo.Abp.Account
{
[RemoteService(Name = IdentityRemoteServiceConsts.RemoteServiceName)]
[Area("identity")]
[RemoteService(Name = AccountRemoteServiceConsts.RemoteServiceName)]
[Area(AccountRemoteServiceConsts.ModuleName)]
[ControllerName("Profile")]
[Route("/api/identity/my-profile")]
[Route("/api/account/my-profile")]
realLiangshiwei marked this conversation as resolved.
Show resolved Hide resolved
public class ProfileController : AbpControllerBase, IProfileAppService
{
protected IProfileAppService ProfileAppService { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Volo.Abp.AspNetCore.Mvc.UI.Theme.Shared.Toolbars;
using Volo.Abp.AutoMapper;
using Volo.Abp.ExceptionHandling;
using Volo.Abp.Http.ProxyScripting.Generators.JQuery;
using Volo.Abp.Identity.AspNetCore;
using Volo.Abp.Modularity;
using Volo.Abp.UI.Navigation;
Expand Down Expand Up @@ -62,6 +63,11 @@ public override void ConfigureServices(ServiceConfigurationContext context)
{
options.AddProfile<AbpAccountWebAutoMapperProfile>(validate: true);
});

Configure<DynamicJavaScriptProxyOptions>(options =>
{
options.DisableModule(AccountRemoteServiceConsts.ModuleName);
});
}

private void ConfigureProfileManagementPage()
Expand All @@ -82,6 +88,7 @@ private void ConfigureProfileManagementPage()
.Configure(typeof(ManageModel).FullName,
configuration =>
{
configuration.AddFiles("/client-proxies/account-proxy.js");
configuration.AddFiles("/Pages/Account/Components/ProfileManagementGroup/Password/Default.js");
configuration.AddFiles("/Pages/Account/Components/ProfileManagementGroup/PersonalInfo/Default.js");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
return;
}

volo.abp.identity.profile.changePassword(input).then(function (result) {
volo.abp.account.profile.changePassword(input).then(function (result) {
abp.message.success(l('PasswordChanged'));
});
});
Expand Down