[Zope3-checkins] CVS: Products3/NewsSite - welcome.pt:1.1 configure.zcml:1.12 register.py:1.2

Tres Seaver tseaver@zope.com
Wed, 26 Mar 2003 15:46:29 -0500


Update of /cvs-repository/Products3/NewsSite
In directory cvs.zope.org:/tmp/cvs-serv6290

Modified Files:
	configure.zcml register.py 
Added Files:
	welcome.pt 
Log Message:


 - Protect syndication policy interface with its own permission.

 - Wire up the registration add form as a page of the NewsSite:
   the view class fakes adding the user to the site by adding it
   to the (presumeably local) authentication service.

   XXX:  Member properties can't be edited yet, due to security.


=== Added File Products3/NewsSite/welcome.pt ===
<html metal:use-macro="views/standard_macros/page">
<head>
<title>Welcome!</title>

</head>
<body>
<div metal:fill-slot="body">

<h1> Welcome to the Site </h1>

</div>
</body>
</html>



=== Products3/NewsSite/configure.zcml 1.11 => 1.12 ===
--- Products3/NewsSite/configure.zcml:1.11	Wed Mar 26 12:59:41 2003
+++ Products3/NewsSite/configure.zcml	Wed Mar 26 15:46:29 2003
@@ -13,6 +13,16 @@
     title="News Site Items"
     />
 
+<permission
+    id="zopeproducts.NewsSite.ManageSyndication"
+    title="Manage Syndication Policies"
+    />
+
+<grant
+    permission="zopeproducts.NewsSite.ManageSyndication"
+    role="Manager"
+    />
+
 <include package=".NewsItem" />
 
 <!-- Configuration for News Site Object
@@ -115,7 +125,9 @@
 <adapter
     factory=".newssite.NewsSiteSyndicationPoliciesAdapter"
     provides=".interfaces.ISyndicationPolicies"
-    for=".interfaces.INewsSite" />
+    for=".interfaces.INewsSite"
+    permission="zopeproducts.NewsSite.ManageSyndication"
+    />
 
 <!-- Use the adapter to edit the syndication policies.
   -->
@@ -130,22 +142,45 @@
     title="Syndication"
     />
 
-
-<!--
+<!-- Registration pages
+  -->
 <browser:addform
     name="register.html"
     schema=".interfaces.IMember"
     label="Registration"
-    permission="zope.Public"
-    for="zope.app.interfaces.security.IAuthenticationService"
+    for=".interfaces.INewsSite"
     class=".register.MemberAddView"
     menu="zmi_actions"
     title="Register"
     arguments="login password"
     set_before_add="email realname"
+    permission="zope.View"
+    />
+
+<adapter
+    factory=".register.MemberDataAdapter"
+    provides=".interfaces.IMember"
+    for="zope.app.interfaces.security.IPrincipal"
+    permission="zope.Security"
+    />
+
+<browser:page
+    name="welcome.html"
+    for=".interfaces.INewsSite"
+    template="welcome.pt"
+    permission="zope.View"
+    />
+
+<browser:editform
+    name="memberdata.html"
+    schema=".interfaces.IMember"
+    label="Member Data"
+    permission="zope.ManageContent"
+    for="zope.app.interfaces.security.IPrincipal"
+    menu="zmi_views"
+    title="Member Data"
     />
 
--->
 <!--
   **
   **    How do we do this?  Should the view class just unwrap the user
@@ -160,5 +195,7 @@
         />
 </content>
   -->
+
+<browser:skin name="news" layers="news rotterdam default" />
 
 </zopeConfigure>


=== Products3/NewsSite/register.py 1.1 => 1.2 ===
--- Products3/NewsSite/register.py:1.1	Tue Mar 25 11:28:00 2003
+++ Products3/NewsSite/register.py	Wed Mar 26 15:46:29 2003
@@ -15,23 +15,94 @@
 
 $Id$
 """
+from persistence.dict import PersistentDict
+
 from zope.component import createObject
+from zope.component import getService
 from zope.component import getAdapter
 
+from zope.app.interfaces.security import IPrincipal
+from zope.app.interfaces.annotation import IAnnotations
+from zope.app.services.servicenames import Authentication
+from zope.app.services.auth import User
+
 from interfaces import IMember
 
 class MemberAddView:
 
     def create(self, login, password):
-        
+
         id = login
         title = ''
         description = ''
 
-        user = createObject(self.context, 'User', id, title, description,
-                            login, password)
+        #user = createObject(self.context, 'User', id, title, description,
+        #                    login, password)
+        user = User( id, title, description, login, password )
         user.setRoles(['Member'])
         return user
 
+    def add(self, content):
+        """Fake out "add", injecting the user into the local auth service.
+        """
+        authsvc = getService(self.context, Authentication)
+        authsvc.setObject(content.getId(), content)
+
     def nextURL(self):
-        return "welcome.html"       
+        return "welcome.html"
+
+
+MDkey = "zopeproducts.NewsSite.MemberData"
+
+class MemberDataAdapter( object ):
+
+    __implements__ = ( IMember, )
+    __used_for__ = ( IPrincipal, )
+
+    _annotations = None
+
+    def __init__( self, context ):
+        self.context = context
+
+        annotations = getAdapter( context, IAnnotations )
+
+        mbrdata = annotations.get( MDkey )
+
+        if not mbrdata:
+            self._annotations = annotations
+            mbrdata = PersistentDict()
+            mbrdata[ 'realname' ] = ''
+            mbrdata[ 'email' ] = ''
+
+        self._mapping = mbrdata
+
+    login = property(lambda self: self.context.getLogin())
+
+    def _getPassword(self):
+        #return self.context.getPassword()
+        return 'PASSWORD' # XXX
+
+    def _setPassword(self, password):
+        #self.context.setPassword(password)
+        pass # XXX
+
+    password = property( _getPassword, _setPassword )
+
+    def _getRealName(self):
+        return self._mapping[ 'realname' ]
+
+    def _setRealName(self, realname):
+        self._mapping[ 'realname' ] = realname
+        self._changed()
+
+    realname = property(_getRealName, _setRealName)
+
+    def _getEmail(self):
+        return self._mapping[ 'email' ]
+
+    def _setEmail(self, email):
+        self._mapping[ 'email' ] = email
+        self._changed()
+
+    email = property(_getEmail, _setEmail)
+