Skip to content

Commit

Permalink
fix some of the tag/category/snippet add/edit behaviors
Browse files Browse the repository at this point in the history
version info tweak
  • Loading branch information
ninianne98 committed Apr 25, 2024
1 parent 8bc8936 commit 3c49a8c
Show file tree
Hide file tree
Showing 13 changed files with 161 additions and 119 deletions.
6 changes: 4 additions & 2 deletions CMSAdmin/CMSAdminCore.csproj
Expand Up @@ -14,8 +14,10 @@
<Authors>Carrotware</Authors>
<Company>Carrotware</Company>
<Copyright>$([System.DateTime]::Now.Year)</Copyright>
<Product Condition="'$(Configuration)' == 'Release'">Carrot Cake CMS, built @ $([System.DateTime]::UtcNow.ToString("yyMMdd")) $([System.DateTime]::UtcNow.ToString("HH:mm"))</Product>
<Product Condition="'$(Configuration)' == 'Debug'">Carrot Cake CMS, debug built @ $([System.DateTime]::UtcNow.ToString("yyMMdd")) $([System.DateTime]::UtcNow.ToString("HH:mm")) DEBUG</Product>
<AppName>Carrot Cake CMS</AppName>
<BuildDateTime>$([System.DateTime]::UtcNow.ToString("yyyy.MM.dd")) $([System.DateTime]::UtcNow.ToString("HH:mm")) UTC</BuildDateTime>
<Product Condition="'$(Configuration)' == 'Release'">$(AppName), built @ $(BuildDateTime)</Product>
<Product Condition="'$(Configuration)' == 'Debug'">$(AppName), debug built @ $(BuildDateTime)</Product>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<VersionPrefix>8.1</VersionPrefix>
<Build>$([System.DateTime]::op_Subtraction($([System.DateTime]::get_Now().get_Date()),$([System.DateTime]::new(2000,1,1))).get_TotalDays())</Build>
Expand Down
59 changes: 30 additions & 29 deletions CMSAdmin/Controllers/CmsAdminApiController.cs
Expand Up @@ -431,10 +431,10 @@ public static class ServiceResponse {
public string ValidateUniqueCategory(string TheSlug, string ItemID) {
try {
Guid CurrentItemGuid = new Guid(ItemID);
TheSlug = CMSConfigHelper.DecodeBase64(TheSlug);
TheSlug = ContentPageHelper.ScrubSlug(TheSlug);
var theSlug = CMSConfigHelper.DecodeBase64(TheSlug);
theSlug = ContentPageHelper.ScrubSlug(theSlug);

int iCount = ContentCategory.GetSimilar(SiteData.CurrentSite.SiteID, CurrentItemGuid, TheSlug);
int iCount = ContentCategory.GetSimilar(SiteData.CurrentSite.SiteID, CurrentItemGuid, theSlug);

if (iCount < 1) {
return JsonSerializer.Serialize(ServiceResponse.OK);
Expand All @@ -453,10 +453,10 @@ public static class ServiceResponse {
public string ValidateUniqueTag(string TheSlug, string ItemID) {
try {
Guid CurrentItemGuid = new Guid(ItemID);
TheSlug = CMSConfigHelper.DecodeBase64(TheSlug);
TheSlug = ContentPageHelper.ScrubSlug(TheSlug);
var theSlug = CMSConfigHelper.DecodeBase64(TheSlug);
theSlug = ContentPageHelper.ScrubSlug(theSlug);

int iCount = ContentTag.GetSimilar(SiteData.CurrentSite.SiteID, CurrentItemGuid, TheSlug);
int iCount = ContentTag.GetSimilar(SiteData.CurrentSite.SiteID, CurrentItemGuid, theSlug);

if (iCount < 1) {
return JsonSerializer.Serialize(ServiceResponse.OK);
Expand All @@ -472,18 +472,18 @@ public static class ServiceResponse {
}

[HttpPost]
public string RecordSnippetHeartbeat(string ItemID) {
public string RecordSnippetHeartbeat([FromBody] ApiModel model) {
try {
Guid CurrentItemGuid = new Guid(ItemID);
Guid CurrentItemGuid = new Guid(model.ItemID);

ContentSnippet item = GetSnippet(CurrentItemGuid);
bool bRet = false;
bool ret = false;

if (item != null && !item.IsLocked) {
bRet = item.RecordSnippetLock(SecurityData.CurrentUserGuid);
ret = item.RecordSnippetLock(SecurityData.CurrentUserGuid);
}

if (bRet) {
if (ret) {
return JsonSerializer.Serialize(SiteData.CurrentSite.Now.ToString());
} else {
return JsonSerializer.Serialize(Convert.ToDateTime("12/31/1899").ToString());
Expand All @@ -497,9 +497,9 @@ public static class ServiceResponse {
}

[HttpPost]
public string CancelSnippetEditing(string ItemID) {
public string CancelSnippetEditing([FromBody] ApiModel model) {
try {
Guid currentItemGuid = new Guid(ItemID);
Guid currentItemGuid = new Guid(model.ItemID);
ContentSnippet item = GetSnippet(currentItemGuid);

if (item != null && !item.IsLocked) {
Expand All @@ -525,20 +525,20 @@ public static class ServiceResponse {
return item;
}

[HttpPost]
[HttpGet]
public string ValidateUniqueSnippet(string TheSlug, string ItemID) {
try {
Guid currentItemGuid = new Guid(ItemID);
TheSlug = CMSConfigHelper.DecodeBase64(TheSlug);
TheSlug = ContentPageHelper.ScrubSlug(TheSlug);
var theSlug = CMSConfigHelper.DecodeBase64(TheSlug);
theSlug = ContentPageHelper.ScrubSlug(theSlug);

ContentSnippet item = GetSnippet(currentItemGuid);

if (item != null) {
currentItemGuid = item.Root_ContentSnippetID;
}

int count = ContentSnippet.GetSimilar(SiteData.CurrentSite.SiteID, currentItemGuid, TheSlug);
int count = ContentSnippet.GetSimilar(SiteData.CurrentSite.SiteID, currentItemGuid, theSlug);

if (count < 1) {
return JsonSerializer.Serialize(ServiceResponse.OK);
Expand Down Expand Up @@ -670,34 +670,34 @@ public static class ServiceResponse {
public string GenerateCategoryTagSlug(string TheSlug, string ItemID, string Mode) {
try {
Guid currentItemGuid = new Guid(ItemID);
TheSlug = CMSConfigHelper.DecodeBase64(TheSlug);
TheSlug = ContentPageHelper.ScrubSlug(TheSlug).ToLowerInvariant();
var theSlug = CMSConfigHelper.DecodeBase64(TheSlug);
theSlug = ContentPageHelper.ScrubSlug(theSlug).ToLowerInvariant();
var matches = 0;
var count = 0;
var siteid = SiteData.CurrentSite.SiteID;

if (Mode.ToLowerInvariant() == "category") {
matches = ContentCategory.GetSimilar(siteid, currentItemGuid, TheSlug);
matches = ContentCategory.GetSimilar(siteid, currentItemGuid, theSlug);
if (matches > 0) {
count = 1;
while (count < 2000 && matches > 0) {
TheSlug = string.Format("{0}-{1}", TheSlug, count);
matches = ContentCategory.GetSimilar(siteid, currentItemGuid, TheSlug);
theSlug = string.Format("{0}-{1}", theSlug, count);
matches = ContentCategory.GetSimilar(siteid, currentItemGuid, theSlug);
}
}
}
if (Mode.ToLowerInvariant() == "tag") {
matches = ContentTag.GetSimilar(siteid, currentItemGuid, TheSlug);
matches = ContentTag.GetSimilar(siteid, currentItemGuid, theSlug);
if (matches > 0) {
count = 1;
while (count < 2000 && matches > 0) {
TheSlug = string.Format("{0}-{1}", TheSlug, count);
matches = ContentTag.GetSimilar(siteid, currentItemGuid, TheSlug);
theSlug = string.Format("{0}-{1}", theSlug, count);
matches = ContentTag.GetSimilar(siteid, currentItemGuid, theSlug);
}
}
}

return JsonSerializer.Serialize(ContentPageHelper.ScrubSlug(TheSlug));
return JsonSerializer.Serialize(ContentPageHelper.ScrubSlug(theSlug));
} catch (Exception ex) {
_logger.LogError(ex, "GenerateCategoryTagSlug");
SiteData.WriteDebugException("webservice", ex);
Expand All @@ -707,11 +707,12 @@ public static class ServiceResponse {
}

[HttpPost]
public string GenerateSnippetSlug(string TheSlug) {
public string GenerateSnippetSlug([FromBody] ApiModel model) {
try {
TheSlug = CMSConfigHelper.DecodeBase64(TheSlug).ToLowerInvariant().Trim();
var theSlug = model.TheSlug;
theSlug = CMSConfigHelper.DecodeBase64(theSlug).ToLowerInvariant().Trim();

return JsonSerializer.Serialize(ContentPageHelper.ScrubSlug(TheSlug));
return JsonSerializer.Serialize(ContentPageHelper.ScrubSlug(theSlug));
} catch (Exception ex) {
_logger.LogError(ex, "GenerateSnippetSlug");
SiteData.WriteDebugException("webservice", ex);
Expand Down
58 changes: 32 additions & 26 deletions CMSAdmin/Controllers/CmsAdminController.cs
Expand Up @@ -100,7 +100,7 @@ public class CmsAdminController : Controller {
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult LogOff() {
SignOut();
ClearUserSession();

SessionContext.CleanExpiredSession();

Expand Down Expand Up @@ -587,7 +587,7 @@ public class CmsAdminController : Controller {
[AllowAnonymous]
public ActionResult DatabaseSetup(string signout) {
if (!string.IsNullOrEmpty(signout)) {
SignOut();
ClearUserSession();
Response.Redirect(SiteFilename.DatabaseSetupURL);
}

Expand All @@ -603,7 +603,7 @@ public class CmsAdminController : Controller {
RedirectIfUsersExist();

if (SecurityData.IsAuthenticated) {
SignOut();
ClearUserSession();

return RedirectToAction(SiteActions.CreateFirstAdmin, new { @signout = true });
}
Expand All @@ -620,7 +620,7 @@ public class CmsAdminController : Controller {
RedirectIfUsersExist();

if (ModelState.IsValid) {
SignOut();
ClearUserSession();

SecurityData sd = new SecurityData();
IdentityUser user = new IdentityUser { UserName = model.UserName, Email = model.Email };
Expand Down Expand Up @@ -838,7 +838,8 @@ public class CmsAdminController : Controller {

if (id.HasValue) {
model = ContentCategory.Get(id.Value);
} else {
}
if (model == null) {
model = new ContentCategory();
model.ContentCategoryID = Guid.Empty;
}
Expand All @@ -850,6 +851,7 @@ public class CmsAdminController : Controller {
[ValidateAntiForgeryToken]
public ActionResult CategoryAddEdit(ContentCategory model) {
Helper.ForceValidation(ModelState, model);
model.ClearOptionalItems(ModelState);

if (ModelState.IsValid) {
ContentCategory item = ContentCategory.Get(model.ContentCategoryID);
Expand Down Expand Up @@ -877,6 +879,7 @@ public class CmsAdminController : Controller {
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult CategoryDelete(ContentCategory model) {
model.ClearOptionalItems(ModelState);
ContentCategory item = ContentCategory.Get(model.ContentCategoryID);
item.Delete();

Expand All @@ -889,7 +892,8 @@ public class CmsAdminController : Controller {

if (id.HasValue) {
model = ContentTag.Get(id.Value);
} else {
}
if (model == null) {
model = new ContentTag();
model.ContentTagID = Guid.Empty;
}
Expand All @@ -901,6 +905,7 @@ public class CmsAdminController : Controller {
[ValidateAntiForgeryToken]
public ActionResult TagAddEdit(ContentTag model) {
Helper.ForceValidation(ModelState, model);
model.ClearOptionalItems(ModelState);

if (ModelState.IsValid) {
ContentTag item = ContentTag.Get(model.ContentTagID);
Expand Down Expand Up @@ -928,6 +933,7 @@ public class CmsAdminController : Controller {
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult TagDelete(ContentTag model) {
model.ClearOptionalItems(ModelState);
ContentTag item = ContentTag.Get(model.ContentTagID);
item.Delete();

Expand Down Expand Up @@ -1161,7 +1167,7 @@ public class CmsAdminController : Controller {
}

[HttpGet]
public ActionResult PageAddEdit(Guid? id, Guid? versionid, Guid? importid, string mode) {
public ActionResult PageAddEdit(Guid? id, Guid? versionid, Guid? importid, string? mode) {
ContentPageModel model = new ContentPageModel();
ContentPage pageContents = model.GetPage(id, versionid, importid, mode);
ViewBag.ContentEditMode = SiteData.EditMode(model.Mode);
Expand Down Expand Up @@ -1271,7 +1277,7 @@ public class CmsAdminController : Controller {
}

[HttpGet]
public ActionResult BlogPostAddEdit(Guid? id, Guid? versionid, Guid? importid, string mode) {
public ActionResult BlogPostAddEdit(Guid? id, Guid? versionid, Guid? importid, string? mode) {
ContentPageModel model = new ContentPageModel();
ContentPage pageContents = model.GetPost(id, versionid, importid, mode);
ViewBag.ContentEditMode = SiteData.EditMode(model.Mode);
Expand All @@ -1284,7 +1290,7 @@ public class CmsAdminController : Controller {
}

[HttpGet]
public ActionResult ContentSnippetAddEdit(Guid? id, Guid? versionid, string mode) {
public ActionResult ContentSnippetAddEdit(Guid? id, Guid? versionid, string? mode) {
ViewBag.ContentEditMode = SiteData.EditMode(mode);

ContentSnippet model = null;
Expand All @@ -1308,7 +1314,7 @@ public class CmsAdminController : Controller {

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult ContentSnippetAddEdit(ContentSnippet model, string mode) {
public ActionResult ContentSnippetAddEdit(ContentSnippet model, string? mode) {
ViewBag.ContentEditMode = SiteData.EditMode(mode);
Helper.ForceValidation(ModelState, model);

Expand Down Expand Up @@ -1393,10 +1399,10 @@ public class CmsAdminController : Controller {
public ActionResult ControlPropertiesEdit(Guid id, Guid pageid) {
cmsHelper.OverrideKey(pageid);

Widget w = (from aw in cmsHelper.cmsAdminWidget
where aw.Root_WidgetID == id
orderby aw.WidgetOrder, aw.EditDate
select aw).FirstOrDefault();
var w = (from aw in cmsHelper.cmsAdminWidget
where aw.Root_WidgetID == id
orderby aw.WidgetOrder, aw.EditDate
select aw).FirstOrDefault();

List<ObjectProperty> lstProps = ObjectProperty.GetWidgetProperties(w);

Expand All @@ -1412,10 +1418,10 @@ public class CmsAdminController : Controller {
public ActionResult ControlPropertiesEdit(WidgetProperties model) {
cmsHelper.OverrideKey(model.Widget.Root_ContentID);

Widget w = (from aw in cmsHelper.cmsAdminWidget
where aw.Root_WidgetID == model.Widget.Root_WidgetID
orderby aw.WidgetOrder, aw.EditDate
select aw).FirstOrDefault();
var w = (from aw in cmsHelper.cmsAdminWidget
where aw.Root_WidgetID == model.Widget.Root_WidgetID
orderby aw.WidgetOrder, aw.EditDate
select aw).FirstOrDefault();

var props = new List<WidgetProps>();

Expand Down Expand Up @@ -1659,7 +1665,7 @@ public class CmsAdminController : Controller {
}

[HttpGet]
public ActionResult ContentEdit(Guid id, Guid? widgetid, string field, string mode) {
public ActionResult ContentEdit(Guid id, Guid? widgetid, string field, string? mode) {
ContentSingleModel model = new ContentSingleModel();
model.Mode = mode;
model.Field = field;
Expand All @@ -1669,9 +1675,9 @@ public class CmsAdminController : Controller {
cmsHelper.OverrideKey(model.PageId);

if (widgetid.HasValue) {
Widget pageWidget = (from w in cmsHelper.cmsAdminWidget
where w.Root_WidgetID == widgetid.Value
select w).FirstOrDefault();
var pageWidget = (from w in cmsHelper.cmsAdminWidget
where w.Root_WidgetID == widgetid.Value
select w).FirstOrDefault();

model.PageText = pageWidget.ControlProperties;
} else {
Expand Down Expand Up @@ -1707,9 +1713,9 @@ public class CmsAdminController : Controller {
if (model.WidgetId.HasValue && model.WidgetId.Value != Guid.Empty) {
List<Widget> lstWidgets = cmsHelper.cmsAdminWidget;

Widget pageWidget = (from w in lstWidgets
where w.Root_WidgetID == model.WidgetId.Value
select w).FirstOrDefault();
var pageWidget = (from w in lstWidgets
where w.Root_WidgetID == model.WidgetId.Value
select w).FirstOrDefault();

pageWidget.ControlProperties = model.PageText;
pageWidget.WidgetDataID = Guid.NewGuid();
Expand Down Expand Up @@ -2916,7 +2922,7 @@ where aw.PlaceholderName.ToLowerInvariant() == model.PlaceholderName.ToLowerInva
return View();
}

protected void SignOut() {
protected void ClearUserSession() {
securityHelper.SignInManager.SignOutAsync();
this.HttpContext.Session.Clear();
}
Expand Down

0 comments on commit 3c49a8c

Please sign in to comment.