I&#39;m not by any means the expert on Jifty, but I&#39;ve given my thoughts below.<br><br>On 8/14/07, <b class="gmail_sendername">Stéphane Alnet</b> &lt;<a href="mailto:stephane@carrierclass.net">stephane@carrierclass.net
</a>&gt; wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello,<br><br>Sorry for the long email. I&#39;m new to Jifty and wanted to evaluate the
<br>complexity of implementing some of the things I need in my application<br>before &quot;making the move&quot;. I especially need:<br><br>(1) Adding constraints on SQL queries:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;I need to be able to filter the display and restrict the insertion
<br>of the content of all Models based on which &quot;group&quot; a user belongs to<br>(groups are stored in the Model alongside the users). Some key SQL<br>tables in my model contain a &quot;group_id/owner_id&quot; pointer to the group
<br>that owns subsets of records (it doesn&#39;t make sense in the model to<br>have all tables have an owning &quot;group&quot; because external dependencies<br>dictate what can be viewed/modified from that selected set of SQL
<br>tables). I already have code that generates SQL fragments on-the-fly<br>to do cross-table constraints (for example, user A can see records<br>WHERE external_id IN (SELECT id FROM external_table WHERE group IN<br>(SELECT group FROM group_user WHERE user = $user)), etc.), but I&#39;m
<br>fine with using something better inside Jifty.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;Is this what RightsFrom implements?<br>&nbsp;&nbsp;&nbsp;&nbsp;RightsFrom seems to only care about &quot;users&quot;, not &quot;groups&quot;, how<br>should I extend this cleanly to support &quot;groups&quot;?
</blockquote><div><br>I&#39;m not precisely clear about what RightsFrom does. To quote the comments in the code &quot;this card is bloody hard to follow. it&#39;s my fault. --jesse&quot; I believe the intention is to basically let you do to the current record whatever you can do to the linked record. However, Jesse or someone with a longer history with Jifty can probably give you more detail.
<br><br>The key to determining whether you can do something in Jifty is defining a current_user_can() method in your models. You can define a common one for all your models by simply adding a definition to you MyApp::Record class. If you have a couple different sets you use, you could use additional custom base classes as well. I&#39;d recommend starting with Jifty::Manual::AccessControl if you have not already.
<br><br>I also highly recommend building up some handy shorthand methods in MyApp::CurrentUser to handle things like testing in_group() and is_owner_of() to help write your current_user_can() methods.<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
(2) Implementing changesets:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;I need to provide the ability to do different things which end up<br>being basically the same thing:<br>&nbsp;&nbsp;&nbsp;&nbsp;- Undo: must be able to reverse a change that was previously done;<br>&nbsp;&nbsp;&nbsp;&nbsp;- Change Control / Policy reviews: a change done by an actor
<br>(user) A may be subject to review by another user B (or a chain / set<br>of actors);<br>&nbsp;&nbsp;&nbsp;&nbsp;- Timed changes: changes are applied at a given date and time (for<br>example for contractual reasons).<br><br>&nbsp;&nbsp;&nbsp;&nbsp;The way I decided to implement this is to define what I call
<br>&quot;ChangeSet&quot;s which basically record the changes that would have been<br>done in the database (which table and columns would have been<br>modified, what are the old and new values, etc.), and depending on the
<br>result to be obtained (simple Undo, Change Control review, timed) will<br>(respectively) apply the ChangeSet immediately, after review, or at a<br>given time (controlled externally).<br><br>&nbsp;&nbsp;&nbsp;&nbsp;In turn, a &quot;commit&quot; of a changeset generates an INSERT/UPDATE
<br>using the &quot;new&quot; values in the ChangeSet (for create/modify), or<br>marking a record as inactive (for delete). Conversely an Undo<br>(reversal) of a changeset involves marking the record inactive (for<br>create), generating an UPDATE using the &quot;old&quot; values in the ChangeSet
<br>(for modify), or marking the record active (for delete); etc.(*)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;To achieve this I need to be able to:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;(a) mark records in the database as active/inactive; only &quot;active&quot;<br>records should be visible within Jifty. My understanding is that the
<br>simplest way to do add such a field is to create a Mixin and use it in<br>each model in my application (the mixin basically adds a boolean<br>&quot;active&quot; column, ..).<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;How would I then filter the records avaible within Jifty?
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Is there a way to implement this within the mixin (i.e. drop<br>the record if &quot;active is not true&quot;)?</blockquote><div><br>I can think of one good way. In general, whenever you need to iterate through a collection of models you do one of two things. You always start by creating a new collection object and then you either call unlimit() to fetch all records or call limit() one or more times to limit which records to fetch. 
<br><br>I would suggest overriding the collection object for the ChangeSet model and then add a limit_to_active() method to use in place of unlimit(). That would make it easy and self-documenting without having to type $collection-&gt;limit(column =&gt; &#39;active&#39;, value =&gt; 0) every time. If you need this for every class in your application, just throw the limit_to_active() method into MyApp::Collection and add the active column to a schema into a mixin included with all your classes (you could even add it to a schema block in MyApp::Record, but intuition tells me that you rarely need to add a column to every single model).
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">&nbsp;&nbsp;&nbsp;&nbsp;(b) replace the standard create/modify/delete in Jifty by versions<br>that implement the ChangeSet mechanism (except for private Jifty
<br>tables and the changeset tables themselves).<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Would creating appropriate delete(), insert() and<br>update_record_value() in MyApp::Handle be sufficient?</blockquote><div><br>Without knowing more about what you&#39;re doing here, I&#39;m not sure what to recommend. There is some work involving records with built-in versioning being done, but it&#39;s in a branch and not finished at this time. 
<br><br>The way it works (last I looked) was to actually store old versions of the records away in Subversion, but I don&#39;t know what state it&#39;s in now, how serious the implementation is, what it&#39;s capable of doing to restore old versions, what the performance characteristics are or anything else. But there has been some work at handling record revisions as a built-in feature of Jifty. 
<br><br>I don&#39;t know if that&#39;s even compatible with your ideas of ChangeSets, but since I can&#39;t answer the question properly, I thought I&#39;d at least let you know about something that sounds similar. And, I haven&#39;t taken the time to look over what you&#39;ve put up on google code. :(
<br></div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">(3) Hiding parts of forms based on a form field:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;I need to show different forms based on the value a user selected
<br>in a field (for example I have a SQL table that store information for<br>different types of trunks; the parameters for each class of trunks are<br>independent; this is similar in spirit to PostgreSQL&#39;s INHERIT<br>
mechanism). I&#39;ve seen Jifty::Manual::PageRegions; but I&#39;m not sure how<br>to use that kind of technics to bind a field (generated by Jifty based<br>on the Model) to showing/hiding a region on the web interface, or
<br>forcing/disabling the validation of field in the Model.<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;What is the proper way of implementing this?</blockquote><div><br>I&#39;m not certain if Jifty supports a way to do this, but adding in the necessary JavaScript shouldn&#39;t be difficult:
<br><br>// in share/web/static/js/app_behaviour.js<br>Behaviour.apply({<br>&nbsp;&nbsp;&nbsp; &#39;input.argument-my_radio&#39;: function(e) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.onclick = function() {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (this.value == &#39;X&#39;) { Element.show
($(&#39;subform-X&#39;)); Element.hide($(&#39;subform-Y&#39;)); }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (this.value == &#39;Y&#39;) { Element.show($(&#39;subform-Y&#39;)); Element.hide($(&#39;subform-X&#39;)); }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };<br>&nbsp;&nbsp;&nbsp; },<br>&nbsp;&nbsp;&nbsp; &#39;
div.subform&#39;: function(e) { Element.hide(e); }<br>});<br><br>I would then wrap those parts of the form in divs marked with &quot;subform-X&quot; and &quot;subform-Y&quot; IDs and &quot;subform&quot; classes.<br><br>If Jifty doesn&#39;t already have a way to do this for you, it&#39;d be nifty to have a subform plugin for this sort of thing.
<br><br>Anyway, I hope at least some of this has been helpful.<br><br>Cheers,<br>Andrew<br></div></div>