Umbraco Node Permissions - umbraco

I have searched for hours and not found the answer to this, so was hoping someone here could help.
How do I get the roles set on a node from code behind?
I have my node: Node nodeToCheck = new Node(nodeID);
How do I now know what role permissions are set on this node?
Thanks in advance.

I just found out how to do this, so thought I would report back here:
string[] roles = Access.GetAccessingMembershipRoles(int.Parse(nodeID), nodeToCheck.Path);
or simpler if you do not want to manually check the roles assigned you can check against the membershipuser
bool hasAccess = Access.HasAccess(int.Parse(nodeID), nodeToCheck.Path, MembershipHelper.GetCurrentUser());

In Umbraco (after 4.7) we can simply do
node.HasAccess // this tells you if the current user has access to that node
Before that we had
node.HasAccess() // or something like that..

Related

How to get all the recent session for a user

I'm using the spring-session project and I find it quite awesome. My requirement is to show the customer a list of his latest logins (IP address, date/time of his latest logins). I'm looking at the SessionRepository but I can't seem to find such a method. Is it possible to introduce such a method to return a org.springframework.data.domain.Page of latest sessions for a given customer? If not could anyone suggest how to tackle this problem?
We want to keep SessionRepository as simple as possible, so it will not be introduced into that API. Instead, we will likely create an extension to the interface when resolving gh-7 is resolved.
In the meantime, you can extend the existing implementation to provide additional methods that map the additional necessary information.
for org.springframework.web.context.request.RequestContextHolder
example usage:
public static HttpSession session() {
ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
return attr.getRequest().getSession(true); // true == allow create
}

ServiceStack - Repository Injection By Name

All,
I have read up on the way SS uses Func to wire registrations. My current issue is that I am still not seeing how to call a specific instance from runtime.
What I would like to do is set up two different repository classes representing two different database systems, say SQLDB and MongoDB, both of which inherit from IDB, then be able to determine which database to use based on an app setting in the config file.
What I have right now in my Configure method is just
container.Register("SQLDB", new TestSQLDB("connectionName"));
container.Register("MongoDB", new TestMongoDB("mongoURL"));
If anyone can help me fill in the blanks I'd appreciate it. I already managed this with Ninject, but I would prefer not to have to add it if I don't need to.
Thanks,
Bs
Register via concrete type (or interface if you prefer):
container.Register<SQLDB>(new TestSQLDB("connectionName"));
container.Register<MongoDB>(new TestMongoDB("mongoURL"));
When you want one back:
var mySqlDB = container.Resolve<SQLDB>();
var myMongoDB = container.Resolve<MongoDB>();
Thanks for your help Gavin. You got me on the right track. Here is what worked.
1) In the config:
container.Register<ITest>("SQLDB", new TestSQLDB("xxxx"));
container.Register<ITest>("MongoDB", new TestMongoDB("mongo://127.0.0.1"));
2) In the service:
IAppHost appHost = base.GetAppHost();
var repository = appHost.GetContainer().ResolveNamed<ITest>("MongoDB");
List<Test> testlist = repository.LoadAll();
This way I can just replace "MongoDB" with something from the config file and I don't need to recompile to change data sources.

zf2 - Retrieve the 'ApplicationConfig' in a 'ActionController'

I realise that there shouldn't be to many reasons for us to access the ApplicationConfig from a controller. But I'm still asking.. Is there a way to do that?
What I actually wishes to do is to get a hold of the
module_listener_options -> config_glob_paths key...
I think #timdev didn't get your point, your question could be solved by:
$applicationConfig = $this->getServiceLocator()->get('ApplicationConfig');
<?php
// in a controller (or anything that is ServiceLocatorAware)
$config = $this->getServiceLocator()->get('Config');
Will give you an array of your application's merged configuration data.

grails removeFrom removes only one at a time

I have a grails application where I have contacts which belongs to another domain contactGroup. It all seems to be working fine except for removeFromContacts method. I am using following code. The code works correctly but removes only one contact from the group at a time. I even did some debugging and the foreach loop runs as many times as the contacts provided. There is no error message. Any idea what could be going wrong -
ContactGroup group = ContactGroup.findByIdAndOwner(params.groupId, user)
def contactIds = request.JSON.data.contact
contactIds.each {
Contact contact = Contact.findByContactIdAndOwner(it.contactId, user)
if(contact) {
group.removeFromContacts(contact)
}
}
I've read a few things about the findAll methods loading proxies if the associations are lazy-loaded rather than the "real" instance.
Try this:
group.removeFromContacts(Contact.get(contact.id))
The 'get' should bypass the proxies and use the "real" instance. There is a JIRA that talks about this (Grails-5804). An overall fix according to the JIRA (from Burt Beckwith) is to implement the equals and hashCode method in your Contact class.
Thanks for all your support. I realized that I have not defined the relationship at the domain level correctly and that was messing up with the whole thing. When I corrected that it was working correctly.
saurabh

How do I update a foreign key relationship in entity framework 4?

I have an object called Account, which has a reference to a timezone through a foreign-key relationship.
On the Account-object I can see the TimeZone_Fk_Id as well as the reference to both Account.TimeZone and Account.TimeZoneReference.
I am trying to update the foreign key relationship but I cannot figure out how.
I have tried all sorts of things. I have tried setting the TimeZone_Fk_Id directly, tried setting the Account.TimeZone to a new timezone, tried updating the entitykeys etc etc. But nothing seems to work. I don't get any exceptions, but when I check the timezone after I supposedly have changed it, it is still the old value.
Any help is greatly appreciated
thanks
Thomas
Have you tried something like
Account account;
TimeZone timeZone;
//Get account instance
//Get timeZone instance to update
account.TimeZone = timeZone;
context.SaveChanges();

Resources