-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the ability to create and edit new permissions in the admin panel
- Loading branch information
support
committed
Sep 22, 2023
1 parent
bf86275
commit e2b6494
Showing
12 changed files
with
559 additions
and
72 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
src/Web/Grand.Web.Admin/Areas/Admin/Views/Permission/Create.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
@model PermissionCreateModel | ||
@{ | ||
Layout = ""; | ||
//page title | ||
ViewBag.Title = Loc["Admin.Configuration.Permissions.AddNew"]; | ||
} | ||
<form id="PermissionPopup" asp-area="@Constants.AreaAdmin" asp-controller="Permission" asp-action="Create" method="post"> | ||
|
||
<div asp-validation-summary="All"></div> | ||
|
||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div class="x_panel light form-fit"> | ||
<div class="x_title"> | ||
<div class="caption"> | ||
<i class="fa fa-cubes"></i> | ||
<text> @Loc["Admin.Configuration.Permissions.AddNew"]</text> | ||
</div> | ||
</div> | ||
<div class="x_content form"> | ||
<div class="form-horizontal"> | ||
<div class="form-body"> | ||
<div class="form-group"> | ||
<admin-label asp-for="Name" /> | ||
<div class="col-md-9 col-sm-9"> | ||
<admin-input asp-for="Name" /> | ||
<span asp-validation-for="Name"></span> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<admin-label asp-for="SystemName" /> | ||
<div class="col-md-9 col-sm-9"> | ||
<admin-input asp-for="SystemName" /> | ||
<span asp-validation-for="SystemName"></span> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<admin-label asp-for="Area" /> | ||
<div class="col-md-9 col-sm-9"> | ||
<admin-input asp-for="Area" /> | ||
<span asp-validation-for="Area"></span> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<admin-label asp-for="Category" /> | ||
<div class="col-md-9 col-sm-9"> | ||
<admin-input asp-for="Category" /> | ||
<span asp-validation-for="Category"></span> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="offset-sm-3 offset-md-3 col-md-9 col-sm-9"> | ||
<button class="btn btn-success" type="submit" name="save"><i class="fa fa-check"></i> @Loc["Admin.Common.Save"] </button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script> | ||
var mfp = $.magnificPopup.instance; | ||
$("#PermissionPopup").submit(function (e) { | ||
e.preventDefault(); | ||
var form = $(this); | ||
var url = form.attr('action'); | ||
$.ajax({ | ||
type: "POST", | ||
url: url, | ||
data: form.serialize(), | ||
success: function (data) { | ||
if (data == "") { | ||
mfp.close(); | ||
location.reload(); | ||
} else { | ||
$.magnificPopup.open({ | ||
items: { | ||
src: data, | ||
type: 'inline' | ||
}, | ||
callbacks: { | ||
open: function () { | ||
$('.mfp-wrap').removeAttr('tabindex'); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
</script> | ||
</form> |
153 changes: 93 additions & 60 deletions
153
src/Web/Grand.Web.Admin/Areas/Admin/Views/Permission/Index.cshtml
Large diffs are not rendered by default.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
src/Web/Grand.Web.Admin/Areas/Admin/Views/Permission/Update.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
@model PermissionUpdateModel | ||
@{ | ||
Layout = ""; | ||
//page title | ||
ViewBag.Title = Loc["Admin.Configuration.Permissions.AddNew"]; | ||
} | ||
<form id="PermissionPopup" asp-area="@Constants.AreaAdmin" asp-controller="Permission" asp-action="Update" method="post"> | ||
<div asp-validation-summary="All"></div> | ||
<input asp-for="Id" type="hidden" /> | ||
<div class="row"> | ||
<div class="col-md-12"> | ||
<div class="x_panel light form-fit"> | ||
<div class="x_title"> | ||
<div class="caption"> | ||
<i class="fa fa-cubes"></i> | ||
<text> @Loc["Admin.Configuration.Permissions.Update"] @Model.SystemName</text> | ||
</div> | ||
</div> | ||
<div class="x_content form"> | ||
<div class="form-horizontal"> | ||
<div class="form-body"> | ||
<div class="form-group"> | ||
<admin-label asp-for="Name" /> | ||
<div class="col-md-9 col-sm-9"> | ||
<admin-input asp-for="Name" /> | ||
<span asp-validation-for="Name"></span> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<admin-label asp-for="SystemName" /> | ||
<div class="col-md-9 col-sm-9"> | ||
<admin-input asp-for="SystemName" asp-disabled="true" /> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<admin-label asp-for="Area" /> | ||
<div class="col-md-9 col-sm-9"> | ||
<admin-input asp-for="Area" /> | ||
<span asp-validation-for="Area"></span> | ||
</div> | ||
</div> | ||
<div class="form-group"> | ||
<admin-label asp-for="Category" /> | ||
<div class="col-md-9 col-sm-9"> | ||
<admin-input asp-for="Category" /> | ||
<span asp-validation-for="Category"></span> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="offset-sm-3 offset-md-3 col-md-9 col-sm-9"> | ||
<button class="btn btn-success" type="submit" name="save"><i class="fa fa-check"></i> @Loc["Admin.Common.Save"] </button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script> | ||
var mfp = $.magnificPopup.instance; | ||
$("#PermissionPopup").submit(function (e) { | ||
e.preventDefault(); | ||
var form = $(this); | ||
var url = form.attr('action'); | ||
$.ajax({ | ||
type: "POST", | ||
url: url, | ||
data: form.serialize(), | ||
success: function (data) { | ||
if (data == "") { | ||
mfp.close(); | ||
location.reload(); | ||
} else { | ||
$.magnificPopup.open({ | ||
items: { | ||
src: data, | ||
type: 'inline' | ||
}, | ||
callbacks: { | ||
open: function () { | ||
$('.mfp-wrap').removeAttr('tabindex'); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
</script> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/Web/Grand.Web.Admin/Extensions/Mapping/PermissionMappingExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Grand.Domain.Permissions; | ||
using Grand.Infrastructure.Mapper; | ||
using Grand.Web.Admin.Models.Permissions; | ||
|
||
namespace Grand.Web.Admin.Extensions.Mapping | ||
{ | ||
public static class PermissionMappingExtensions | ||
{ | ||
public static Permission ToEntity(this PermissionCreateModel model) | ||
{ | ||
return model.MapTo<PermissionCreateModel, Permission>(); | ||
} | ||
|
||
public static PermissionUpdateModel ToModel(this Permission entity) | ||
{ | ||
return entity.MapTo<Permission, PermissionUpdateModel>(); | ||
} | ||
|
||
public static Permission ToEntity(this PermissionUpdateModel model, Permission destination) | ||
{ | ||
return model.MapTo(destination); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using AutoMapper; | ||
using Grand.Domain.Permissions; | ||
using Grand.Infrastructure.Mapper; | ||
using Grand.Web.Admin.Models.Permissions; | ||
|
||
namespace Grand.Web.Admin.Mapper; | ||
|
||
public class PermissionProfile : Profile, IAutoMapperProfile | ||
{ | ||
public PermissionProfile() | ||
{ | ||
CreateMap<PermissionCreateModel, Permission>(); | ||
CreateMap<PermissionUpdateModel, Permission>() | ||
.ForMember(dest => dest.Id, mo => mo.Ignore()) | ||
.ForMember(dest => dest.SystemName, mo => mo.Ignore()) | ||
.ForMember(dest => dest.Actions, mo => mo.Ignore()) | ||
.ForMember(dest => dest.CustomerGroups, mo => mo.Ignore()); | ||
|
||
CreateMap<Permission, PermissionUpdateModel>(); | ||
} | ||
|
||
public int Order => 0; | ||
} |
31 changes: 31 additions & 0 deletions
31
src/Web/Grand.Web.Admin/Models/Permissions/PermissionCreateModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Grand.Infrastructure.ModelBinding; | ||
using Grand.Infrastructure.Models; | ||
|
||
namespace Grand.Web.Admin.Models.Permissions; | ||
|
||
public class PermissionCreateModel : BaseModel | ||
{ | ||
/// <summary> | ||
/// Gets or sets the permission name | ||
/// </summary> | ||
[GrandResourceDisplayName("Admin.Configuration.Permissions.Fields.Name")] | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the permission system name | ||
/// </summary> | ||
[GrandResourceDisplayName("Admin.Configuration.Permissions.Fields.SystemName")] | ||
public string SystemName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the area name | ||
/// </summary> | ||
[GrandResourceDisplayName("Admin.Configuration.Permissions.Fields.Area")] | ||
public string Area { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the permission category | ||
/// </summary> | ||
[GrandResourceDisplayName("Admin.Configuration.Permissions.Fields.Category")] | ||
public string Category { get; set; } | ||
} |
Oops, something went wrong.