2007-12-03 23:34:35 +00:00
|
|
|
from Persistent import Persistent, quote
|
|
|
|
|
|
|
|
|
|
|
|
class Invite( Persistent ):
|
|
|
|
"""
|
|
|
|
An invitiation to view or edit a notebook.
|
|
|
|
"""
|
|
|
|
def __init__( self, object_id, revision = None, from_user_id = None, notebook_id = None,
|
2008-01-04 04:45:43 +00:00
|
|
|
email_address = None, read_write = False, owner = False, redeemed_user_id = None,
|
|
|
|
redeemed_username = None ):
|
2007-12-03 23:34:35 +00:00
|
|
|
"""
|
|
|
|
Create an invitation with the given id.
|
|
|
|
|
|
|
|
@type object_id: unicode
|
|
|
|
@param object_id: id of the invitation
|
|
|
|
@type revision: datetime or NoneType
|
|
|
|
@param revision: revision timestamp of the object (optional, defaults to now)
|
|
|
|
@type from_user_id: unicode or NoneType
|
|
|
|
@param from_user_id: id of the user who sent the invite (optional)
|
|
|
|
@type notebook_id: unicode or NoneType
|
2007-12-04 21:28:03 +00:00
|
|
|
@param notebook_id: id of the notebook that the invitation is for
|
2007-12-03 23:34:35 +00:00
|
|
|
@type email_address: unicode or NoneType
|
|
|
|
@param email_address: where the invitation was emailed (optional)
|
|
|
|
@type read_write: bool or NoneType
|
|
|
|
@param read_write: whether the invitation is for read-write access (optional, defaults to False)
|
|
|
|
@type owner: bool or NoneType
|
|
|
|
@param owner: whether the invitation is for owner-level access (optional, defaults to False)
|
|
|
|
@type redeemed_user_id: unicode or NoneType
|
|
|
|
@param redeemed_user_id: id of the user who has redeemed this invitation, if any (optional)
|
2008-01-04 04:45:43 +00:00
|
|
|
@type redeemed_username: unicode or NoneType
|
|
|
|
@param redeemed_username: username of the user who has redeemed this invitation, if any (optional)
|
2007-12-03 23:34:35 +00:00
|
|
|
@rtype: Invite
|
|
|
|
@return: newly constructed notebook invitation
|
|
|
|
"""
|
|
|
|
Persistent.__init__( self, object_id, revision )
|
|
|
|
self.__from_user_id = from_user_id
|
|
|
|
self.__notebook_id = notebook_id
|
|
|
|
self.__email_address = email_address
|
|
|
|
self.__read_write = read_write
|
|
|
|
self.__owner = owner
|
|
|
|
self.__redeemed_user_id = redeemed_user_id
|
2008-01-04 04:45:43 +00:00
|
|
|
self.__redeemed_username = redeemed_username
|
2007-12-03 23:34:35 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def create( object_id, from_user_id = None, notebook_id = None, email_address = None, read_write = False, owner = False ):
|
|
|
|
"""
|
|
|
|
Convenience constructor for creating a new invitation.
|
|
|
|
|
|
|
|
@type object_id: unicode
|
|
|
|
@param object_id: id of the invitation
|
|
|
|
@type from_user_id: unicode or NoneType
|
|
|
|
@param from_user_id: id of the user who sent the invite (optional)
|
|
|
|
@type notebook_id: unicode or NoneType
|
2007-12-04 21:28:03 +00:00
|
|
|
@param notebook_id: id of the notebook that the invitation is for
|
2007-12-03 23:34:35 +00:00
|
|
|
@type email_address: unicode or NoneType
|
|
|
|
@param email_address: where the invitation was emailed (optional)
|
|
|
|
@type read_write: bool or NoneType
|
|
|
|
@param read_write: whether the invitation is for read-write access (optional, defaults to False)
|
|
|
|
@type owner: bool or NoneType
|
|
|
|
@param owner: whether the invitation is for owner-level access (optional, defaults to False)
|
|
|
|
@rtype: Invite
|
|
|
|
@return: newly constructed notebook invitation
|
|
|
|
"""
|
|
|
|
return Invite( object_id, from_user_id = from_user_id, notebook_id = notebook_id,
|
|
|
|
email_address = email_address, read_write = read_write, owner = owner )
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def sql_load( object_id, revision = None ):
|
|
|
|
# password resets don't store old revisions
|
|
|
|
if revision:
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
2008-01-04 04:45:43 +00:00
|
|
|
return \
|
|
|
|
"""
|
|
|
|
select
|
|
|
|
invite.id, invite.revision, invite.from_user_id, invite.notebook_id, invite.email_address,
|
|
|
|
invite.read_write, invite.owner, invite.redeemed_user_id, luminotes_user_current.username
|
|
|
|
from
|
|
|
|
invite left outer join luminotes_user_current
|
|
|
|
on
|
|
|
|
( invite.redeemed_user_id = luminotes_user_current.id )
|
|
|
|
where
|
|
|
|
invite.id = %s;
|
|
|
|
""" % quote( object_id )
|
2007-12-03 23:34:35 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def sql_id_exists( object_id, revision = None ):
|
|
|
|
if revision:
|
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
|
|
return "select id from invite where id = %s;" % quote( object_id )
|
|
|
|
|
|
|
|
def sql_exists( self ):
|
|
|
|
return Invite.sql_id_exists( self.object_id )
|
|
|
|
|
|
|
|
def sql_create( self ):
|
|
|
|
return "insert into invite ( id, revision, from_user_id, notebook_id, email_address, read_write, owner, redeemed_user_id ) values ( %s, %s, %s, %s, %s, %s, %s, %s );" % \
|
|
|
|
( quote( self.object_id ), quote( self.revision ), quote( self.__from_user_id ), quote( self.__notebook_id ),
|
|
|
|
quote( self.__email_address ), quote( self.__read_write and "t" or "f" ), quote( self.__owner and "t" or "f" ),
|
|
|
|
quote( self.__redeemed_user_id ) )
|
|
|
|
|
|
|
|
def sql_update( self ):
|
|
|
|
return "update invite set revision = %s, from_user_id = %s, notebook_id = %s, email_address = %s, read_write = %s, owner = %s, redeemed_user_id = %s where id = %s;" % \
|
2007-12-11 01:15:03 +00:00
|
|
|
( quote( self.revision ), quote( self.__from_user_id ), quote( self.__notebook_id ),
|
2007-12-03 23:34:35 +00:00
|
|
|
quote( self.__email_address ), quote( self.__read_write and "t" or "f" ), quote( self.__owner and "t" or "f" ),
|
2007-12-11 01:15:03 +00:00
|
|
|
quote( self.__redeemed_user_id ), quote( self.object_id ) )
|
2007-12-03 23:34:35 +00:00
|
|
|
|
2007-12-06 22:05:00 +00:00
|
|
|
def sql_load_similar( self ):
|
2007-12-18 00:05:13 +00:00
|
|
|
# select invites with the same notebook_id, and email_address as this invite
|
2008-01-04 04:45:43 +00:00
|
|
|
return \
|
|
|
|
"""
|
|
|
|
select
|
|
|
|
invite.id, invite.revision, invite.from_user_id, invite.notebook_id, invite.email_address,
|
|
|
|
invite.read_write, invite.owner, invite.redeemed_user_id, luminotes_user_current.username
|
|
|
|
from
|
|
|
|
invite left outer join luminotes_user_current
|
|
|
|
on
|
|
|
|
( invite.redeemed_user_id = luminotes_user_current.id )
|
|
|
|
where
|
|
|
|
invite.notebook_id = %s and invite.email_address = %s and invite.id != %s;
|
|
|
|
""" % ( quote( self.__notebook_id ), quote( self.__email_address ), quote( self.object_id ) )
|
2007-12-06 22:05:00 +00:00
|
|
|
|
2007-12-12 00:52:34 +00:00
|
|
|
@staticmethod
|
|
|
|
def sql_load_notebook_invites( notebook_id ):
|
2008-01-04 04:45:43 +00:00
|
|
|
# select a list of invites to the given notebook
|
|
|
|
return \
|
|
|
|
"""
|
|
|
|
select
|
|
|
|
invite.id, invite.revision, invite.from_user_id, invite.notebook_id, invite.email_address,
|
|
|
|
invite.read_write, invite.owner, invite.redeemed_user_id, luminotes_user_current.username
|
|
|
|
from
|
|
|
|
invite left outer join luminotes_user_current
|
|
|
|
on
|
|
|
|
( invite.redeemed_user_id = luminotes_user_current.id )
|
|
|
|
where
|
|
|
|
invite.notebook_id = %s
|
|
|
|
order by
|
|
|
|
invite.email_address, invite.redeemed_user_id;
|
|
|
|
""" % quote( notebook_id )
|
2007-12-12 00:52:34 +00:00
|
|
|
|
2007-12-14 01:53:12 +00:00
|
|
|
def sql_revoke_invites( self ):
|
|
|
|
return "delete from invite where notebook_id = %s and email_address = %s;" % \
|
|
|
|
( quote( self.__notebook_id ), quote( self.__email_address ) )
|
|
|
|
|
2007-12-12 00:52:34 +00:00
|
|
|
def to_dict( self ):
|
|
|
|
d = Persistent.to_dict( self )
|
|
|
|
d.update( dict(
|
|
|
|
from_user_id = self.__from_user_id,
|
|
|
|
notebook_id = self.__notebook_id,
|
|
|
|
email_address = self.__email_address,
|
|
|
|
read_write = self.__read_write,
|
|
|
|
owner = self.__owner,
|
|
|
|
redeemed_user_id = self.__redeemed_user_id,
|
2008-01-04 04:45:43 +00:00
|
|
|
redeemed_username = self.__redeemed_username,
|
2007-12-12 00:52:34 +00:00
|
|
|
) )
|
|
|
|
|
|
|
|
return d
|
|
|
|
|
2007-12-06 22:05:00 +00:00
|
|
|
def __set_read_write( self, read_write ):
|
|
|
|
if read_write != self.__read_write:
|
|
|
|
self.update_revision()
|
|
|
|
self.__read_write = read_write
|
|
|
|
|
|
|
|
def __set_owner( self, owner ):
|
|
|
|
if owner != self.__owner:
|
|
|
|
self.update_revision()
|
|
|
|
self.__owner = owner
|
|
|
|
|
2007-12-03 23:34:35 +00:00
|
|
|
def __set_redeemed_user_id( self, redeemed_user_id ):
|
|
|
|
if redeemed_user_id != self.__redeemed_user_id:
|
|
|
|
self.update_revision()
|
|
|
|
self.__redeemed_user_id = redeemed_user_id
|
|
|
|
|
|
|
|
from_user_id = property( lambda self: self.__from_user_id )
|
|
|
|
notebook_id = property( lambda self: self.__notebook_id )
|
|
|
|
email_address = property( lambda self: self.__email_address )
|
2007-12-06 22:05:00 +00:00
|
|
|
read_write = property( lambda self: self.__read_write, __set_read_write )
|
|
|
|
owner = property( lambda self: self.__owner, __set_owner )
|
2007-12-03 23:34:35 +00:00
|
|
|
redeemed_user_id = property( lambda self: self.__redeemed_user_id, __set_redeemed_user_id )
|
2008-01-04 04:45:43 +00:00
|
|
|
redeemed_username = property( lambda self: self.__redeemed_username )
|