Editing a property of an object if user user is not authorized to edit the base data itself

Feb 10, 2012 at 8:28 AM

Just an interesting issue. Lets's say we have Cars and FuelTypes in our model, and User and Admin roles. Among other properties, Cars have a specified FuelType. I want User to be able to edit all properties os Cars, but none of FuelTypes, and want to grant Admin editing everything.

Based on our previous discussion, tagging the

public IQueryable<...> AllInstances()

method with AuthorizeAction attribute within the Respository, the FuelTypes menu service is not visible to the User, that just works fine. But if User edits a Car, User is unable to modify the FuelType property of any Cars. Only the Remove and the Recently Viewed menus are visible under the Find menu. (I think because the AllInstances() method of the FuelTypeRespository is not accessible for the User and because of this a list of FuelTypes cannot be populated to choose from)

When Admin edits a Car, everything is OK because he sees the FuelTypes menu.

Is there any way to grant the user the possibility of changing the FuelType of a Car without granting him the editing of FuelType itself?

Coordinator
Feb 10, 2012 at 8:58 AM

"Is there any way to grant the user the possibility of changing the FuelType of a Car without granting him the editing of FuelType itself?"

Yes, this is quite straightforward.  You need to be controlling authorization at the level of the object properties.  So on on the FuelType class, each property should be marked up, say:

[AuthorizeProperty(ViewRoles="Admin, User", EditRoles="Admin")]

 Incidentally, I would imagine that there weren't many FuelTypes  -  so should this not be a [Bounded] class, so that Car.FuelType appears as a drop-down rather than needed to rely on the Find Menu and AllInstances in order to specify it.

Feb 10, 2012 at 5:33 PM

Thanks! Bounded is what I was looking for. Nevertheless, AuthorizeProperty is also useful for me for some purpose. Thank you again for your help.

Feb 14, 2012 at 1:48 PM

Another question, connected with this topic.

When I tag FuelType with the Bounded attribute, a dropdown is shown when editing. Can I specify the order on the items of the dropdown? Like implementing a Sort method within the FuelType class or something like that.

Editor
Feb 14, 2012 at 1:55 PM
I don't think you can.

However, NO/EF is probably just doing a "select *" on the underlying table, so if you add a clustered index on the desired column then (with a bit of luck) it'll come back in the desired order...

Dan


On 14 February 2012 13:48, dtereanszky <notifications@codeplex.com> wrote:

From: dtereanszky

Another question, connected with this topic.

When I tag FuelType with the Bounded attribute, a dropdown is shown when editing. Can I specify the order on the items of the dropdown? Like implementing a Sort method within the FuelType class or something like that.

Read the full discussion online.

To add a post to this discussion, reply to this email (nakedobjects@discussions.codeplex.com)

To start a new discussion for this project, email nakedobjects@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Coordinator
Feb 14, 2012 at 1:58 PM
Edited Feb 14, 2012 at 1:59 PM

If you want to control ordering of choices in a drop-down  then use a choices method corresponding to the property name e.g.:

public IList<FuelType> ChoicesFuelType() { 
  return Container.Instances<FuelType>().OrderBy(x => x.CarbonFootprint).ToList();
}

The code snippet for this is 'propcho'.  Note that you can also use this approach to filter-down a list of choices.

Editor
Feb 14, 2012 at 2:00 PM
But Dean was asking about how to control the implicit drop-down of [Bounded]?


On 14 February 2012 13:58, richardpawson <notifications@codeplex.com> wrote:

From: richardpawson

If you want to control ordering of choices in a drop-down then use a choices method corresponding to the property name e.g.:

public IList<FuelType> ChoicesFuelType() { 
  return Container.Instances<FuelType>().OrderBy(x = x.CarbonFootprint).ToList();
}

The code snippet for this is 'propcho'. Note that you can also use this approach to filter-down a list of choices.

Read the full discussion online.

To add a post to this discussion, reply to this email (nakedobjects@discussions.codeplex.com)

To start a new discussion for this project, email nakedobjects@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Feb 14, 2012 at 3:23 PM

Richard, this what I was looking for. Just one more question (sorry for being so lame). Which class should I put this method into? I tried both FuelTypeRepository and CarRepository, but the result was only that "Choices Fuel Type" menu appeared under both menu. My objects are generated from an edmx file, so they do not have a Container. Should I place one into my classes?

Coordinator
Feb 14, 2012 at 6:49 PM

This method should be in the class( classes) that has the property of type FuelType.  I think you said you had a Car with a FuelType property.  In which case you need to have a ChoicesFuelType in the Car class  -  adjacent (though only for readability) to the FuelType property.

I think you should spend some time reading the developer manual  -  there are probably hundreds of tricks you are missing at present.  Look in the section called Adding behaviour to your domain objects  -  a how-to guide.