[Zope-CMF] Content types & user roles question

Adrian Madrid aem@byu.edu
Fri, 13 Apr 2001 11:23:28 -0700 (PDT)


I've been wondering that myself and so far I the only
thing I have come up with is a shameless hack that
follows. 


<!-- Inside cycle of content_types available -->
<form action="invokeFactory" method="POST">
<table cellpadding="2">

 <!-- Folder -->
 <tr valign="middle">
  <td> <input type="radio" name="type_name"
value="Folder" id="cb_2" /> </td>
  <td colspan="2"> <label for="cb_2"><dtml-var
"z3po(_.None, _, ident='Folder')"></label> </td>
 <tr valign="top">
  <td> <br> </td>
  <td> <br> </td>
  <td valign="top"><dtml-var "z3po(_.None, _,
ident='FolderExplanation')"></td>
 </tr>

 <!-- Link -->
 <tr valign="middle">
  <td> <input type="radio" name="type_name"
value="Link" id="cb_1" /> </td>
  <td colspan="2"> <label for="cb_1"><dtml-var
"z3po(_.None, _, ident='Link')"></label> </td>
 <tr valign="top">
  <td> <br> </td>
  <td> <br> </td>
  <td valign="top"><dtml-var "z3po(_.None, _,
ident='LinkExplanation')"></td>
 </tr>

 <!-- Favorite -->
 <tr valign="middle">
  <td> <input type="radio" name="type_name"
value="Favorite" id="cb_3" /> </td>
  <td colspan="2"> <label for="cb_3"><dtml-var
"z3po(_.None, _, ident='Favorite')"></label> </td>
 <tr valign="top">
  <td> <br> </td>
  <td> <br> </td>
  <td valign="top"><dtml-var "z3po(_.None, _,
ident='FavoriteExplanation')"></td>
 </tr>

<dtml-if "'Staff' in
_.SecurityGetUser().getRolesInContext(Portal)">
 <!-- Document -->
 <tr valign="middle">
  <td> <input type="radio" name="type_name"
value="Document" id="cb_0" /> </td>
  <td colspan="2"> <label for="cb_0"><dtml-var
"z3po(_.None, _, ident='Document')"></label> </td>
 <tr valign="top">
  <td> <br> </td>
  <td> <br> </td>
  <td valign="top"><dtml-var "z3po(_.None, _,
ident='DocumentExplanation')"></td>
 </tr>

 <!-- File -->
 <tr valign="middle">
  <td> <input type="radio" name="type_name"
value="File" id="cb_6" /> </td>
  <td colspan="2"> <label for="cb_6"><dtml-var
"z3po(_.None, _, ident='File')"></label> </td>
 <tr valign="top">
  <td> <br> </td>
  <td> <br> </td>
  <td valign="top"><dtml-var "z3po(_.None, _,
ident='FileExplanation')"></td>
 </tr>
 
 <!-- Poll -->
 <tr valign="middle">
  <td> <input type="radio" name="type_name"
value="Poll" id="cb_4" /> </td>
  <td colspan="2"> <label for="cb_4"><dtml-var
"z3po(_.None, _, ident='Poll')"></label> </td>
 <tr valign="top">
  <td> <br> </td>
  <td> <br> </td>
  <td valign="top"><dtml-var "z3po(_.None, _,
ident='PollExplanation')"></td>
 </tr>

 <!-- News Item -->
 <tr valign="middle">
  <td> <input type="radio" name="type_name"
value="News Item" id="cb_7" /> </td>
  <td colspan="2"> <label for="cb_7"><dtml-var
"z3po(_.None, _, ident='News Item')"></label> </td>
 <tr valign="top">
  <td> <br> </td>
  <td> <br> </td>
  <td valign="top"><dtml-var "z3po(_.None, _,
ident='NewsItemExplanation')"></td>
 </tr>

 <!-- ID and Add button -->
 <tr valign="top">
  <td> <br> </td>
  <td colspan="2"> <strong> ID: </strong>
       <input type="text" name="id" size="20">
       <input type="submit" value="<dtml-var
"z3po(_.None, _, ident='Add')">"> </td>
 </tr>

</table>
</form>

In skins/generic you'll find the method
folder_factories that is called when a member clicks
on New in their desktops. I have taken part of the
generated source and added a conditional to let
different users select depending on their roles.
General members get to create Folders, Links and
Favorites while Staff members can create the rest. The
bit that will interest you the most is:

<dtml-if "'Staff' in
_.SecurityGetUser().getRolesInContext(Portal)">

Thanks to Tres and Nick for their help on finding out
how to tell if somebody has a certain role.

WARNING: This method does NOT use the rights mechanism
and therefore is insecure in that, ie., normal members
could still create documents although they will have
to know zope, dtml, etc.

Anyway, hope it helps,



=====
---------------------------
Adrian Esteban Madrid
Benson Institute, Webmaster
Brigham Young University
---------------------------
adrian_esteban@madrid.com
===========================

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail. 
http://personal.mail.yahoo.com/