bug 1801 : Better understanding of how 'Assert...' methods are supposed to work, leading to simpler code.

This commit is contained in:
sb 2008-04-17 17:33:16 +00:00
parent fd3bfabe3a
commit 4efb909880

View file

@ -9,8 +9,8 @@
Transform ADL into (partial) controller classes
$Author: sb $
$Revision: 1.20 $
$Date: 2008-04-17 16:16:19 $
$Revision: 1.21 $
$Date: 2008-04-17 17:33:16 $
-->
<!-- WARNING WARNING WARNING: Do NOT reformat this file!
@ -71,7 +71,7 @@
//
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
// Automatically generated from application description using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.20 $', 10)"/>
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.21 $', 10)"/>
//
// This file is automatically generated; DO NOT EDIT IT.
//
@ -128,7 +128,7 @@ namespace <xsl:value-of select="$controllerns"/> {
//
// Controller for auto-generated forms for editing <xsl:value-of select="@name"/>s
// Automatically generated from application description using
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.20 $', 10)"/>
// adl2controllerclasses.xslt version <xsl:value-of select="substring( '$Revision: 1.21 $', 10)"/>
//
// This file is automatically generated; DO NOT EDIT IT.
//
@ -194,8 +194,8 @@ namespace <xsl:value-of select="$controllerns"/> {
</xsl:call-template>
if ( record == null) {
if ( AssertUserCanCreate()) {
/* it seems to be new, create persistent object */
AssertUserCanCreate()
try {
record = new <xsl:value-of select="concat($entityns, '.', @name)"/>(<xsl:for-each select="adl:key/adl:property">
<xsl:variable name="basetype">
@ -240,15 +240,14 @@ namespace <xsl:value-of select="$controllerns"/> {
messages.Add( "New <xsl:value-of select="@name"/> record created");
isnewborn = true;
}
else
{
AddError( "You are not authorised to create objects of type <xsl:value-of select="@name"/>");
}
}
if ( record != null) {
if ( isnewborn || AssertUserCanUpdate())
{
if ( ! isnewborn) {
// isnewborn cannot be true unless we've already checked user can create
// so no need to do it again here
AssertUserCanUpdate();
}
try {
/* actually update the record */
BindObjectInstance( record, ParamStore.Form, "instance");
@ -380,8 +379,6 @@ namespace <xsl:value-of select="$controllerns"/> {
hibernator.Flush();
messages.Add( "Record saved successfully");
}
catch ( DataSuitabilityException dse)
{
@ -391,10 +388,6 @@ namespace <xsl:value-of select="$controllerns"/> {
{
AddError( axe.Message);
}
}
else {
AddError( "You are not authorised to update objects of type <xsl:value-of select="@name"/>");
}
PropertyBag["messages"] = messages;
PropertyBag["instance"] = record;
@ -433,8 +426,7 @@ namespace <xsl:value-of select="$controllerns"/> {
[AccessibleThrough(Verb.Post)]
public void Delete()
{
if ( AssertUserCanDelete())
{
AssertUserCanDelete();
ISession hibernator =
NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]</xsl:if>);
@ -466,9 +458,6 @@ namespace <xsl:value-of select="$controllerns"/> {
Redirect( FormsAuthentication.DefaultUrl);
</xsl:otherwise>
</xsl:choose>
} else {
AddError( "You are not authorised to delete objects of type <xsl:value-of select="@name"/>");
}
}
</xsl:if>
<xsl:apply-templates select="adl:form"/>
@ -492,7 +481,7 @@ namespace <xsl:value-of select="$controllerns"/> {
/// &lt;param name="view"&gt;The name of the list view to show&lt;/param&gt;
public void InternalShowList( String view)
{
if ( AssertUserCanRead()) {
AssertUserCanRead();
ISession hibernator =
NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]</xsl:if>);
@ -508,9 +497,6 @@ namespace <xsl:value-of select="$controllerns"/> {
PaginationHelper.CreatePagination( this, instances, 25);
RenderViewWithFailover(view + ".vm", view + ".auto.vm");
} else {
AddError( "You are not authorised to delete view of type <xsl:value-of select="@name"/>");
}
}
</xsl:if>
}
@ -604,6 +590,8 @@ namespace <xsl:value-of select="$controllerns"/> {
[AccessibleThrough(Verb.Get)]
public void <xsl:value-of select="@name"/>( )
{
AssertUserCanRead();
ISession hibernator =
NHibernateHelper.GetCurrentSession( <xsl:if test="$authentication-layer = 'Database'">Session[ NHibernateHelper.USERTOKEN],
Session[NHibernateHelper.PASSTOKEN]</xsl:if>);