I have Umbraco User Id (not current user id) and published content Id, how can I check that user is able to see this content?
I found this api:
Access.HasAccess(int documentId, memberId)
But it`s marked as obsolete. Any other ways to achieve this?
For current member you should user the UmbracoHelper.MemberHasAccess method
https://our.umbraco.org/documentation/reference/querying/umbracohelper/
So as an example you could something like this to display the children of the current page the member has access to:
var children = Model.Content.Children.Where(c => Umbraco.MemberHasAccess(c.Path));
But you say it's not for the current member so can you extend you questions to understand what you are trying to do?
I am using this:
int memberId;
int nodeId;
var publicAccessService = ApplicationContext.Current.Services.PublicAccessService;
var contentService = ApplicationContext.Current.Services.ContentService;
var memberService = ApplicationContext.Current.Services.MemberService;
var member = memberService.GetById(memberId);
var rolesList = Roles.GetRolesForUser(member.Username);
if(publicAccessService.HasAccess(nodeId, contentService, rolesList))
{
// has access
}
{
// does NOT have access
}
Related
In Umbraco 7 I used the following code to generate code programmatically from C# (controller)
using ContentService.CreateContent
And following is the code for the same
int parentID = 1100;
var request = ContentService.CreateContent("New Node Name", parentID, ContactUsForm.ModelTypeAlias);
request.SetValue(ContactRequestItem.GetModelPropertyType(C => C.FirstName).PropertyTypeAlias, FormModel.FirstName);
ContentService.PublishWithStatus(request);
Now in Umbraco 8
it is asking for
Udi ParentId
getting error "Can not convert 'int' to 'Umbraco.Core.Uid' ".
Have searched a lot, but can't find anything for Umbraco 8.
So now the question is How we can create a node from a controller in Umbraco 8?
How about getting the parent node first (this can be done via int ID) and then get the UDI from that? Something like
var parent = ContentService.GetById(1100);
var request = ContentService.CreateContent("New Node Name", parent.GetUdi(), ContactUsForm.ModelTypeAlias);
The solution is as suggested on the following the link
on the Umbraco Forum
public IContentService _contentService { get; set; }
public TestController(IContentService contentService)
{
_contentService = contentService;
}
public override ActionResult Index(ContentModel model)
{
var parentId = new Guid("3cce2545-e3ac-44ec-bf55-a52cc5965db3");
var request = _contentService.Create("test", parentId, ContentPage.ModelTypeAlias);
_contentService.SaveAndPublish(request);
return View();
}
In Umbraco 8, you need the parent Udi to create a new node. You can do this by getting the parent node first then getting the Udi using the parent node like this:
var parentNode = ContentService.GetById(1100);
var parentUdi = new GuidUdi(parentNode.ContentType.ToString(), parentNode.Key);
You can then call the CreateContent method and pass in the parentUdi as a parameter:
var request = ContentService.CreateContent("New Node Name", parentUdi, ContactUsForm.ModelTypeAlias);
ContentService.SaveAndPublish(request);
I'm trying to create new member programaticaly.
In fact I need to build a function to import members from a spreadsheet.
I build a Member class which inherits ProfileBase and can create one member programaticaly when he registers but that requires he logs in to update full profile.
So a member registers, his membership is created, I log him in, create his profile and log him out. This is not visible for the user but works well in the background.
Now I need to to import members through a feature in the umbraco back office.
I am able to create members but I am unable to update their profiles which use custom properties set up in web.config, umbraco and my Member class. I just get empty profile in my database.
Any idea what I can do in this case? How I can update a member profile without logging the member in?
Thank you
I did something very similar myself recently, assuming your Member class looks something like the following (or at least does the same thing).
public class MemberProfile : ProfileBase
{
#region Firstname
private const string FIRSTNAME = "_firstname";
[SettingsAllowAnonymous(false)]
public string FirstName
{
get
{
return GetCustomProperty(FIRSTNAME);
}
set
{
SetCustomProperty(FIRSTNAME, value);
}
}
#endregion
#region Get and Set base properties
private string GetCustomProperty(string propertyName)
{
var retVal = "";
var prop = base.GetPropertyValue(propertyName);
if (prop != null)
{
retVal = prop.ToString();
}
return retVal;
}
private void SetCustomProperty(string propertyName, object value)
{
var prop = base[propertyName];
if (prop != null)
{
base.SetPropertyValue(propertyName, value);
}
}
#endregion
}
Then using the following method should allow you to retrieve a member, update a property and save them:
var existingMember = MemberProfile.Create(username) as MemberProfile;
existingMember.FirstName = firstName;
existingMember.Save();
The confusing bit is that the Create() method actually returns existing users, they just called it create for some reason...
I am trying to subscribe to CheckinEvent in TFS 2010 using TFS IEventService. For some reason I keep getting:
Event type <<event type>> does not exist
for WorkItemChangedEvent and CheckinEvent. What am I doing wrong?
var serverUri = new Uri("http://TFS_SERVICE:8080/tfs");
var server = TfsConfigurationServerFactory.GetConfigurationServer(serverUri);
var eventService = server.GetService<IEventService>();
var preference = new DeliveryPreference
{
Schedule = DeliverySchedule.Immediate,
Type = DeliveryType.Soap,
Address = "http://localhost:61773/NotifyService.asmx"
};
int eventId = eventService.SubscribeEvent("CheckinEvent", null, preference);
You are querying the Event Service at the Configuration Server level. These event types only exist at the team project collection level, which I assume is where you actually want to create your event subscription. You would need to change your code to something like the following:
var serverUri = new Uri("http://TFS_SERVICE:8080/tfs/collection");
TfsTeamProjectCollection collection = new TfsTeamProjectCollection(serverUri);
var eventService = collection.GetService<IEventService>();
var preference = new DeliveryPreference
{
Schedule = DeliverySchedule.Immediate,
Type = DeliveryType.Soap,
Address = "http://localhost:61773/NotifyService.asmx"
};
int eventId = eventService.SubscribeEvent("CheckinEvent", null, preference);
Please note that the URI needs to include your collection name.
Instead of using the TfsConfigurationServerFactory, use the TfsTeamProjectCollectionFactory.GetTeamProjectCollection() method. These events exist at the collection level, rather than the server level.
I am looking up users who are members of an AD group using GroupPrincipal.
GroupPrincipal group = GroupPrincipal.FindByIdentity(pc, "Advisors");
I need to get the EmployeeID field from this lookup but I believe this is only possible using UserPrincipal.
var members = group.Members.Select(x => new DomainContext() { EmployeeID = x.EmployeeId, FullName = x.DisplayName }).ToList();
Does anyone know of a way round this?
You have to use UserPrincipal unless you're using the underlying DirectoryEntry/DirectorySearcher classes.
You should use .GetMembers() instead of .Members then you can do stuff like:
var userMembers = group.GetMembers().OfType<UserPrincipal>();
foreach( var member in userMembers) {
string empid = member.EmployeeId; //do something with the EmployeeId
}
I thought this would be really simple but ..
We've create a user and a member type with various properties
When we try to access the properties via the member object we got nothing.
//Member m is current User
eg.
Property s = m.getProperty("PreferdUserName");
is null
m.getProperties has a count of Zero..
have we missed something obvious?
Could there be a spelling error?
"PreferdUserName" may want to be "PreferredUserName".
Other than that it looks correct.
In the end i resorted to storing member properties in a separate db table, which anyhow is closer to what i need.
I presume it had something to do with the way I created the memberType from outside umbraco using a custom msbuild task.
You could create your own class and extend ProfileBase. The code below will expose the properties that you have created within Umbraco. e.g. umbraco alias is 'first_name'.
[SettingsAllowAnonymous(false)]
public string FirstName
{
get
{
var o = base.GetPropertyValue("first_name");
if (o == DBNull.Value)
{
return string.Empty;
}
return (string)o;
}
set
{
base.SetPropertyValue("first_name", value);
}
}
Then you can access properties like so...
string firstName = ((MemberProfile)HttpContext.Current.Profile).FirstName;
More info about how to set this all up can be seen here:
http://www.aaron-powell.com/posts/2010-04-07-umbraco-members-profiles.html
This might help someone else, if you need to get member details for someone other than the current user in Umbraco and have their Username.
var TheirUsername = "s12345";
Member MemberFind = new Member(Convert.ToInt32(Membership.GetUser(***TheirUsername***).ProviderUserKey));
//now use this value
var NameOfUser = MemberFind.Text;
var EmailAddress = MemberFind.Email;
Try
Property s = m.getProperty("PreferdUserName").value;
If that still doesn't work, then check out this great post about member properties
http://legacy.aaron-powell.com/blog/july-2009/umbraco-member-profiles.aspx