How to set Public Access Member Role On a form Post
Hello, and thanks in advance.
I am trying to make the data entered into a form visible to a specific member group that I created. I am Able to post the data to Umbraco without an issue, but I am unable to find clear documentation about setting the Public Access for the Post. here is what I have below.
public ActionResult HandleFormPost(WarrantyModel model) //Links functions to the form in the partial view...BeginUmbracoForm
{
if (ModelState.IsValid) // For Field Validation
{
// This will post submittion to Umbraco Database
var newWarranty = Services.ContentService.CreateContent(model.WarLastName + "-" + DateTime.Now, 1204, "warrantyFormula");
var myService = ApplicationContext.Services.DataTypeService;
string InstallType = model.WarInstallType;
string Applications = model.WarApplication;
string PurchasedFroms = model.WarPurchasedFrom;
int ColorValue = model.WarColor;
var ColorNode = new Node(ColorValue);
newWarranty.SetValue("WarInstallDate", model.WarInstallDate);
newWarranty.SetValue("WarSqFt", model.WarSqFt);
newWarranty.SetValue("WarInstallType", InstallType);
newWarranty.SetValue("WarApplication", Applications);
newWarranty.SetValue("WarColor", ColorNode.Name);
newWarranty.SetValue("WarFabCompany", model.WarFabCompany);
newWarranty.SetValue("WarFabAddress", model.WarFabAddress);
newWarranty.SetValue("WarFabCity", model.WarFabCity);
newWarranty.SetValue("WarFabSt", model.WarFabSt);
newWarranty.SetValue("WarFabZip", model.WarFabZip);
newWarranty.SetValue("WarFabCountry", model.WarFabCountry);
newWarranty.SetValue("WarFabPhone", model.WarFabPhone);
newWarranty.SetValue("umbracoNaviHide", true);
Services.ContentService.SaveAndPublishWithStatus(newWarranty);
// Set Member Role Access
int newWarrantyId = model.Id;
var publicAccessService = ApplicationContext.Current.Services.PublicAccessService;
var entry = publicAccessService.GetEntryForContent(newWarrantyId);
entry.LoginNodeId = 1447;
entry.NoAccessNodeId = 1097;
entry.AddRule("MemberRole", "Warranty Admin");
publicAccessService.Save(entry);
}
}
I think I am Trying to Get the ID of the Post that was just saved and Published, and then update the Public Access mode, Login page, error page, and the member group. Every test I do does not apply the member group.
Thanks for your response. I am aware of how to set up the access manually, but I need to do it from the controller because the node is created from the form post by the public user. once the data is submitted I don't want the new page/content to be public
I found The answer to this post Here. the Answer is from Bo Jacobsen.
here is what changed in the controller:
...
newWarranty.SetValue("WarFabZip", model.WarFabZip);
newWarranty.SetValue("WarFabCountry", model.WarFabCountry);
newWarranty.SetValue("WarFabPhone", model.WarFabPhone);
newWarranty.SetValue("umbracoNaviHide", true);
Services.ContentService.SaveAndPublishWithStatus(newWarranty);
// Set Member Role Access
// Umbraco Services
var publicAccessService = ApplicationContext.Current.Services.PublicAccessService;
var contentService = ApplicationContext.Current.Services.ContentService;
// If entry does not exists, create one this way.
var loginPage = contentService.GetById(1447);
var noAccessPage = contentService.GetById(1097);
var entry = new PublicAccessEntry(newWarranty, loginPage, noAccessPage, new List<PublicAccessRule>());
publicAccessService.Save(entry);
// After the new entry is saved, you can add new rule this way.
// Or if you just wanna add rules and not LoginNodeId and NoAccessNodeId.
// If entry is null. This won't work.
var roleBasedProtectionAttempt = publicAccessService.AddRule(newWarranty, "MemberRole", "Warranty Admin");
How to set Public Access Member Role On a form Post
Hello, and thanks in advance.
I am trying to make the data entered into a form visible to a specific member group that I created. I am Able to post the data to Umbraco without an issue, but I am unable to find clear documentation about setting the Public Access for the Post. here is what I have below.
I think I am Trying to Get the ID of the Post that was just saved and Published, and then update the Public Access mode, Login page, error page, and the member group. Every test I do does not apply the member group.
Does anybody have any insight? I keep getting errors that the entry variable is null or no set. I am not able to get the ID of the newly created Data
Hi,
I dunno how to do it, but I am actually managing the public acces lie that...
Thanks for your response. I am aware of how to set up the access manually, but I need to do it from the controller because the node is created from the form post by the public user. once the data is submitted I don't want the new page/content to be public
I found The answer to this post Here. the Answer is from Bo Jacobsen.
here is what changed in the controller:
is working on a reply...