示例#1
0
 def share( self, trans, id=None, email="", use_panels=False ):
     """ Handle sharing a visualization with a particular user. """
     msg = mtype = None
     visualization = self.get_visualization( trans, id, check_ownership=True )
     if email:
         other = trans.sa_session.query( model.User ) \
                                 .filter( and_( model.User.table.c.email==email,
                                                model.User.table.c.deleted==False ) ) \
                                 .first()
         if not other:
             mtype = "error"
             msg = ( "User '%s' does not exist" % email )
         elif other == trans.get_user():
             mtype = "error"
             msg = ( "You cannot share a visualization with yourself" )
         elif trans.sa_session.query( model.VisualizationUserShareAssociation ) \
                 .filter_by( user=other, visualization=visualization ).count() > 0:
             mtype = "error"
             msg = ( "Visualization already shared with '%s'" % email )
         else:
             share = model.VisualizationUserShareAssociation()
             share.visualization = visualization
             share.user = other
             session = trans.sa_session
             session.add( share )
             self.create_item_slug( session, visualization )
             session.flush()
             trans.set_message( "Visualization '%s' shared with user '%s'" % ( visualization.title, other.email ) )
             return trans.response.send_redirect( url_for(controller='visualization', action='sharing', id=id ) )
     return trans.fill_template( "/ind_share_base.mako",
                                 message = msg,
                                 messagetype = mtype,
                                 item=visualization,
                                 email=email,
                                 use_panels=use_panels )
示例#2
0
 def share(self, trans, id=None, email="", use_panels=False):
     """ Handle sharing a visualization with a particular user. """
     msg = mtype = None
     visualization = self.get_visualization(trans, id, check_ownership=True)
     if email:
         other = trans.sa_session.query(model.User) \
                                 .filter(and_(model.User.table.c.email == email,
                                              model.User.table.c.deleted == false())) \
                                 .first()
         if not other:
             mtype = "error"
             msg = f"User '{escape(email)}' does not exist"
         elif other == trans.get_user():
             mtype = "error"
             msg = ("You cannot share a visualization with yourself")
         elif trans.sa_session.query(model.VisualizationUserShareAssociation) \
                 .filter_by(user=other, visualization=visualization).count() > 0:
             mtype = "error"
             msg = f"Visualization already shared with '{escape(email)}'"
         else:
             share = model.VisualizationUserShareAssociation()
             share.visualization = visualization
             share.user = other
             session = trans.sa_session
             session.add(share)
             self.slug_builder.create_item_slug(session, visualization)
             session.flush()
             viz_title = escape(visualization.title)
             other_email = escape(other.email)
             trans.set_message(
                 f"Visualization '{viz_title}' shared with user '{other_email}'"
             )
             return trans.response.send_redirect(
                 web.url_for(f"/visualizations/sharing?id={id}"))
     return trans.fill_template("/ind_share_base.mako",
                                message=msg,
                                messagetype=mtype,
                                item=visualization,
                                email=email,
                                use_panels=use_panels)