diff --git a/transforms01/adl2controllerclasses.xslt b/transforms01/adl2controllerclasses.xslt
index a5bd808..b45a080 100755
--- a/transforms01/adl2controllerclasses.xslt
+++ b/transforms01/adl2controllerclasses.xslt
@@ -9,8 +9,8 @@
Transform ADL into (partial) controller classes
$Author: sb $
- $Revision: 1.19 $
- $Date: 2008-04-17 15:04:15 $
+ $Revision: 1.20 $
+ $Date: 2008-04-17 16:16:19 $
-->
@@ -209,12 +214,12 @@ namespace {
- hibernator.CreateCriteria( typeof( ))
- .Add(Expression.Eq( "",
+ hibernator.CreateCriteria( typeof( ))
+ .Add(Expression.Eq( "",
Int32.Parse( Form[ ""])
Form[ ""]
))
- .UniqueResult<>()
+ .UniqueResult<>()
Form[""]
@@ -222,62 +227,70 @@ namespace {
,
);
+ }
+ catch ( FormatException) {
+ /* failed to parse a number - not wholly unexpected, since it's most likely
+ that an empty string was passed in */
+ record = new ();
+ }
+ catch ( NullReferenceException) {
+ /* again, probably more normal than otherwise */
+ record = new ();
+ }
+ messages.Add( "New record created");
+ isnewborn = true;
}
- catch ( FormatException) {
- /* failed to parse a number - not wholly unexpected, since it's most likely
- that an empty string was passed in */
- record = new ();
+ else
+ {
+ AddError( "You are not authorised to create objects of type ");
}
- catch ( NullReferenceException) {
- /* again, probably more normal than otherwise */
- record = new ();
- }
- messages.Add( "New record created");
}
if ( record != null) {
- try {
- /* actually update the record */
- BindObjectInstance( record, ParamStore.Form, "instance");
+ if ( isnewborn || AssertUserCanUpdate())
+ {
+ try {
+ /* actually update the record */
+ BindObjectInstance( record, ParamStore.Form, "instance");
- /* there is at least one slot whose value is an internationalised message;
- * if these have yet to be initialised they must be handled specially */
- Locale locale = GetBestLocaleForUser();
+ /* there is at least one slot whose value is an internationalised message;
+ * if these have yet to be initialised they must be handled specially */
+ Locale locale = GetBestLocaleForUser();
- if ( ! String.IsNullOrEmpty( Form[""])){
- /* there's an uninitialised message for this slot */
- Message mess = record.;
- if ( mess == null){
- mess = new Message();
- }
- hibernator.Save( mess);
+ if ( ! String.IsNullOrEmpty( Form[""])){
+ /* there's an uninitialised message for this slot */
+ Message mess = record.;
+ if ( mess == null){
+ mess = new Message();
+ }
+ hibernator.Save( mess);
- Translation trans = mess.GetTranslationObject( locale, hibernator);
- if ( trans == null) {
- trans = new Translation( mess, locale);
+ Translation trans = mess.GetTranslationObject( locale, hibernator);
+ if ( trans == null) {
+ trans = new Translation( mess, locale);
+ }
+ trans.MessageText = Form[""];
+ record. = mess;
+ hibernator.Save( trans);
}
- trans.MessageText = Form[""];
- record. = mess;
- hibernator.Save( trans);
- }
- /* for properties of type 'entity', it should not be necessary to do anything
- * special - BindObjectInstance /should/ do it all. Unfortunately it sometimes
- * doesn't, and I haven't yet characterised why not. */
+ /* for properties of type 'entity', it should not be necessary to do anything
+ * special - BindObjectInstance /should/ do it all. Unfortunately it sometimes
+ * doesn't, and I haven't yet characterised why not. */
- if ( ! String.IsNullOrEmpty( Form[""]))
- {
- record. =
-
-
- ;
- }
+ if ( ! String.IsNullOrEmpty( Form[""]))
+ {
+ record. =
+
+
+ ;
+ }
@@ -289,92 +302,98 @@ namespace {
- /* to update a link table which has no other data than the near and far keys, it is
- * sufficient to smash the existing values and create new ones. It's also a lot easier! */
+ /* to update a link table which has no other data than the near and far keys, it is
+ * sufficient to smash the existing values and create new ones. It's also a lot easier! */
- string[] = Form.GetValues( "");
+ string[] = Form.GetValues( "");
- if ( != null)
- {
- /* update the linking table for my ; first smash the old values */
- if ( != null)
+ if ( != null)
{
- .Clear();
- }
- else
- {
- = new HashedSet<>();
- }
+ /* update the linking table for my ; first smash the old values */
+ if ( != null)
+ {
+ .Clear();
+ }
+ else
+ {
+ = new HashedSet<>();
+ }
- /* then reinstate the values from the indexes passed */
- foreach ( string index in )
- {
- .Add(
- hibernator.CreateCriteria(typeof())
- .Add(Expression.Eq("Id", index))
- .UniqueResult<.>());
+ /* then reinstate the values from the indexes passed */
+ foreach ( string index in )
+ {
+ .Add(
+ hibernator.CreateCriteria(typeof())
+ .Add(Expression.Eq("Id", index))
+ .UniqueResult<.>());
+ }
}
- }
- /* with a list we cannot just smash the old values! Instead we need to check
- * each one and exclude it if no longer required */
- if ( Form.GetValues( "") != null)
- {
- string[] = Form.GetValues( "");
-
- /* updating child records; first remove any not on the submitted list */
- foreach ( item in record.)
+ /* with a list we cannot just smash the old values! Instead we need to check
+ * each one and exclude it if no longer required */
+ if ( Form.GetValues( "") != null)
{
- String itemId = item.KeyString;
- bool found = false;
+ string[] = Form.GetValues( "");
- foreach ( string index in )
+ /* updating child records; first remove any not on the submitted list */
+ foreach ( item in record.)
{
-
- if ( index.Equals( itemId))
+ String itemId = item.KeyString;
+ bool found = false;
+
+ foreach ( string index in )
{
- found = true;
+
+ if ( index.Equals( itemId))
+ {
+ found = true;
+ }
+ }
+
+ if ( ! found)
+ {
+ record..Remove( item);
}
}
-
- if ( ! found)
- {
- record..Remove( item);
- }
- }
- /* then add any on the included list which are not already members */
- foreach ( string index in )
- {
-
- item =
- hibernator.CreateCriteria(typeof())
- .Add(Expression.Eq("Id", index))
- .UniqueResult<.>();
-
- if ( ! record..Contains( item))
+ /* then add any on the included list which are not already members */
+ foreach ( string index in )
{
- record..Add( item);
+
+ item =
+ hibernator.CreateCriteria(typeof())
+ .Add(Expression.Eq("Id", index))
+ .UniqueResult<.>();
+
+ if ( ! record..Contains( item))
+ {
+ record..Add( item);
+ }
}
}
- }
- /* write the record to the database, in order to guarantee we have a valid key */
- hibernator.Save(record);
- hibernator.Flush();
+ /* write the record to the database, in order to guarantee we have a valid key */
+ hibernator.Save(record);
+ hibernator.Flush();
- messages.Add( "Record saved successfully");
+ messages.Add( "Record saved successfully");
+
+
+ }
+ catch ( DataSuitabilityException dse)
+ {
+ AddError( dse.Message);
+ }
+ catch ( ApplicationException axe)
+ {
+ AddError( axe.Message);
+ }
}
- catch ( DataSuitabilityException dse)
- {
- AddError( dse.Message);
- }
- catch ( ApplicationException axe)
- {
- AddError( axe.Message);
+ else {
+ AddError( "You are not authorised to update objects of type ");
}
PropertyBag["messages"] = messages;
@@ -414,37 +433,42 @@ namespace {
[AccessibleThrough(Verb.Post)]
public void Delete()
{
- ISession hibernator =
+ if ( AssertUserCanDelete())
+ {
+ ISession hibernator =
NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]);
- string reallydelete = Params["reallydelete"];
+ string reallydelete = Params["reallydelete"];
- if ( "true".Equals( reallydelete))
- {
+ if ( "true".Equals( reallydelete))
+ {
- if ( record != null)
- {
- hibernator.Delete( record);
+ if ( record != null)
+ {
+ hibernator.Delete( record);
- hibernator.Flush();
+ hibernator.Flush();
+ }
+ else
+ {
+ throw new ApplicationException( "No such record?");
+ }
}
- else
- {
- throw new ApplicationException( "No such record?");
- }
- }
- Redirect( "");
+ Redirect( "");
- Redirect( FormsAuthentication.DefaultUrl);
+ Redirect( FormsAuthentication.DefaultUrl);
+ } else {
+ AddError( "You are not authorised to delete objects of type ");
+ }
}
@@ -468,21 +492,25 @@ namespace {
/// <param name="view">The name of the list view to show</param>
public void InternalShowList( String view)
{
- ISession hibernator =
- NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN],
+ if ( AssertUserCanRead()) {
+ ISession hibernator =
+ NHibernateHelper.GetCurrentSession( Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]);
- IList<> instances =
- hibernator.CreateCriteria(typeof())
-
- .List<>();
+ IList<> instances =
+ hibernator.CreateCriteria(typeof())
+
+ .List<>();
-
- PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN];
-
- PropertyBag["instances"] =
- PaginationHelper.CreatePagination( this, instances, 25);
+
+ PropertyBag["username"] = Session[ NHibernateHelper.USERTOKEN];
+
+ PropertyBag["instances"] =
+ PaginationHelper.CreatePagination( this, instances, 25);
- RenderViewWithFailover(view + ".vm", view + ".auto.vm");
+ RenderViewWithFailover(view + ".vm", view + ".auto.vm");
+ } else {
+ AddError( "You are not authorised to delete view of type ");
+ }
}
}