예제 #1
0
 def create(cls, user, email, obj, role=APP_ROLE_READ):
     """
     Invites a user to an object.
     
     Params are supposed to be:
         user invites email to obj with role
     
     This will find the user if he already exists.
     """
     cls._setup_lookups()
     
     if role not in APP_ROLES:
         raise ex.AppException('Check your role(%s) param' % (type, role), ex.INVALID)
     
     if not obj or not user or type(obj).__name__ not in cls.put_types:
         raise ex.AppException('Check your user and org params. They must not be None.' % (type, role), ex.INVALID)
     
     type_ = cls.put_types[type(obj).__name__].strip()
     
     invited = Session.query(User).filter_by(email=email).first()
     invites = Session.query(Invite).filter_by(invited_email=email, object_id=obj.id, type=type_)
     invites = invites.filter(Invite.status.in_([STATUS_APPROVED, STATUS_PENDING])).first()
     
     if (invited and obj.get_role(invited)) or invites:
         raise ex.AppException('User has already been added to this %s' % type(obj).__name__, ex.DUPLICATE)
     
     inv = Invite(role=role, type=type_, invited_email=email,
                  user=user, invited_user=invited,
                  object_id=obj.id, status=STATUS_PENDING)
     Session.flush()
     
     Session.add(activity.InviteEvent(user, inv))
     
     return inv
예제 #2
0
 def set_completion_status(self, user, status):
     cs = CommentStatus(user=user, status=status, comment=self)
     Session.add(cs)
     Session.flush()
     
     Session.add(activity.CommentComplete(cs))
     
     return cs
예제 #3
0
 def completion_status(self):
     """
     Users can 'complete' comments.
     
     This will get the most recent row from CommentStatus.
     Should be either 'open' or 'completed'
     """
     cs = Session.query(CommentStatus).filter_by(comment_id=self.id).order_by(sa.desc(CommentStatus.created_date)).first()
     if not cs:
         #create a default
         cs = CommentStatus(user=self.creator, created_date=self.created_date, status=STATUS_OPEN, comment=self)
         Session.add(cs)
         Session.flush()
     return cs
예제 #4
0
 def add_comment(self, user, body, x=None, y=None, width=None, height=None, in_reply_to=None):
     """
     Add a new comment to this ChangeExtract.
     """
     entity = None
     if hasattr(self, 'entity_id'):
         entity = self.entity
     elif hasattr(self, 'change'):
         entity = self.change.entity
     
     comment = Comment(creator=user, body=body, x=x, y=y, width=width, height=height, in_reply_to=in_reply_to, **{self._comment_attribute: self})
     Session.add(comment)
     Session.flush()
     
     if in_reply_to:
         Session.add(activity.NewReply(user, entity, comment))
     else:
         Session.add(activity.NewComment(user, entity, comment))
     
     return comment
예제 #5
0
    def add_change(self, user, temp_contents_filepath, description):
        """
        Introduce a new change in the given changeset using the file stored
        at temp_contents_filepath with the given description for the change.
        """
        size = 0
        if temp_contents_filepath:
            size = os.stat(temp_contents_filepath).st_size

        change = Change(description=description,
                        size=size,
                        entity=self,
                        project=self.project,
                        creator=user)
        change.digest = digests.md5_file(temp_contents_filepath)
        Session.add(change)
        Session.flush()
        change.set_contents(temp_contents_filepath)
        self.update_activity()
        return change
예제 #6
0
def flush():
    """Wrapper fn"""
    Session.flush()
예제 #7
0
def commit():
    """wrapper fn"""
    if utils.is_testing():
        Session.flush()
    else:
        Session.commit()
예제 #8
0
def flush():
    """Wrapper fn"""
    Session.flush()
예제 #9
0
def commit():
    """wrapper fn"""
    if utils.is_testing():
        Session.flush()
    else:
        Session.commit()