def list_permissions(cls, node): if node.access == 'public': users = User.query(User.organization == node.organization) else: owner = User.get_by_gid(node.owner) # list collaborators edge_list = Edge.list(start_node=node.key, kind='permissions') users_list_of_keys = [] for edge in edge_list['items']: users_list_of_keys.append(edge.end_node) users = ndb.get_multi(users_list_of_keys) users.append(owner) return users
def require_iogrow_user(cls, action=None): token = endpoints.users_id_token._get_token(None) token_stored = Tokens.query(Tokens.token == token).get() if token_stored: return token_stored.user.get() token = endpoints.users_id_token._get_token(None) # will get the token info from the dict token_info = _SAVED_TOKEN_DICT.get(token) if token_info is None: # will get the token info from network result = cls.get_token_info(token) if result.status_code != 200: raise endpoints.UnauthorizedException(cls.INVALID_TOKEN) token_info = json.loads(result.content) _SAVED_TOKEN_DICT[token] = token_info if 'email' not in token_info: raise endpoints.UnauthorizedException(cls.INVALID_TOKEN) email = token_info['email'] user_from_email = User.get_by_email(email) if user_from_email is None: raise endpoints.UnauthorizedException(cls.NO_ACCOUNT) store_new_token = Tokens(token=token, user=user_from_email.key, email=user_from_email.email) store_new_token.put() return user_from_email
def list_permissions(cls, node): if node.access == 'public': users = User.query(User.organization == node.organization) else: owner = User.get_by_gid(node.owner) # list collaborators edge_list = Edge.list( start_node=node.key, kind='permissions' ) users_list_of_keys = [] for edge in edge_list['items']: users_list_of_keys.append(edge.end_node) users = ndb.get_multi(users_list_of_keys) users.append(owner) return users
def share_related_documents_after_patch(cls, user, old_obj, new_obj): # from private to access if old_obj.access == 'private' and new_obj.access == 'public': users = User.query(User.organization == user.organization) for collaborator in users: if collaborator.email != user.email: taskqueue.add(url='/workers/shareobjectdocument', queue_name='iogrow-low', params={ 'email': collaborator.email, 'obj_key_str': old_obj.key.urlsafe() }) if hasattr(old_obj, 'profile_img_id'): if old_obj.profile_img_id != new_obj.profile_img_id and new_obj.profile_img_id != "": taskqueue.add(url='/workers/sharedocument', queue_name='iogrow-low', params={ 'user_email': user.email, 'access': 'anyone', 'resource_id': new_obj.profile_img_id }) if hasattr(old_obj, 'logo_img_id'): if old_obj.logo_img_id != new_obj.logo_img_id and new_obj.logo_img_id != "": taskqueue.add(url='/workers/sharedocument', queue_name='iogrow-low', params={ 'user_email': user.email, 'access': 'anyone', 'resource_id': new_obj.logo_img_id })
def predict(predd, tedd): user = User.get_by_email('*****@*****.**') credentials = user.google_credentials http = credentials.authorize(httplib2.Http()) service = build('prediction', 'v1.6', http=http) result = service.trainedmodels().predict(project='935370948155-qm0tjs62kagtik11jt10n9j7vbguok9d', id='7', body={ 'input': {'csvInstance': ['Sofware Engineer', 'Purchase List']}}).execute() return result
def who_has_access(cls, obj_key): acl = {} obj = obj_key.get() owner_gid = obj.owner owner = User.get_by_gid(owner_gid) collaborators = [] edge_list = iograph.Edge.list(start_node=obj_key, kind='permissions') for edge in edge_list['items']: collaborator = edge.end_node.get() if collaborator: collaborators.append(collaborator) acl['owner'] = owner acl['collaborators'] = collaborators return acl
def predict(predd, tedd): user = User.get_by_email('*****@*****.**') credentials = user.google_credentials http = credentials.authorize(httplib2.Http()) service = build('prediction', 'v1.6', http=http) result = service.trainedmodels().predict( project='935370948155-qm0tjs62kagtik11jt10n9j7vbguok9d', id='7', body={ 'input': { 'csvInstance': ['Sofware Engineer', 'Purchase List'] } }).execute() return result
def share_related_documents_after_patch(cls, user, old_obj, new_obj): # from private to access if old_obj.access == 'private' and new_obj.access == 'public': users = User.query(User.organization == user.organization) for collaborator in users: if collaborator.email != user.email: taskqueue.add( url='/workers/shareobjectdocument', queue_name='iogrow-low', params={ 'email': collaborator.email, 'obj_key_str': old_obj.key.urlsafe() } ) if hasattr(old_obj, 'profile_img_id'): if old_obj.profile_img_id != new_obj.profile_img_id and new_obj.profile_img_id != "": taskqueue.add( url='/workers/sharedocument', queue_name='iogrow-low', params={ 'user_email': user.email, 'access': 'anyone', 'resource_id': new_obj.profile_img_id } ) if hasattr(old_obj, 'logo_img_id'): if old_obj.logo_img_id != new_obj.logo_img_id and new_obj.logo_img_id != "": taskqueue.add( url='/workers/sharedocument', queue_name='iogrow-low', params={ 'user_email': user.email, 'access': 'anyone', 'resource_id': new_obj.logo_img_id } )
def receive(self, mail_message): sender_id = mail_message.to.split("@")[0] try: bcc = mail_message.bcc.split("@")[0] except: bcc = 'undefined' user_id = 'undefined' if sender_id.isdigit(): user_id = sender_id if bcc.isdigit(): user_id = bcc user = User.get_by_gid(user_id) if user: sender_email = re.findall(r'[\w\.-]+@[\w\.-]+', mail_message.sender) if user.email == sender_email[0]: print 'authorized' html_bodies = mail_message.bodies('text/html') email_body = '' additional_emails = ' ' for content_type, body in html_bodies: decoded_html = smart_str(body.decode()) email_body += decoded_html additional_emails += ' ' + smart_str(mail_message.to) try: additional_emails += ' ' + smart_str(mail_message.bcc) except: pass try: additional_emails += ' ' + smart_str(mail_message.cc) except: pass re_emails = re.findall(r'[\w\.-]+@[\w\.-]+', email_body + additional_emails) emails = list(set(re_emails)) print 'emails' print emails for email in emails: generic_prop = ndb.GenericProperty() generic_prop._name = 'email' nodes = Node.query(generic_prop == email).fetch() if len(nodes) > 0: for node in nodes: parents_edge_list = Edge.list(start_node=node.key, kind='parents') for edge in parents_edge_list['items']: parent_key = edge.end_node # insert a note related to the parent node note_author = Userinfo() note_author.display_name = user.google_display_name note_author.photo = user.google_public_profile_photo_url note = Note(owner=user.google_user_id, organization=user.organization, author=note_author, title=mail_message.subject, content=email_body) entityKey_async = note.put_async() entityKey = entityKey_async.get_result() Edge.insert(start_node=parent_key, end_node=entityKey, kind='topics', inverse_edge='parents') EndpointsHelper.update_edge_indexes( parent_key=entityKey, kind='topics', indexed_edge=str(parent_key.id())) else: pass # We should create a lead related to this email # and attach this email with this lead else: print 'not authorized' else: print 'user doesnt exist'
def receive(self, mail_message): sender_id = mail_message.to.split("@")[0] try: bcc = mail_message.bcc.split("@")[0] except: bcc = 'undefined' user_id = 'undefined' if sender_id.isdigit(): user_id=sender_id if bcc.isdigit(): user_id=bcc user = User.get_by_gid(user_id) if user: sender_email=re.findall(r'[\w\.-]+@[\w\.-]+', mail_message.sender) if user.email==sender_email[0]: print 'authorized' html_bodies = mail_message.bodies('text/html') email_body = '' additional_emails = ' ' for content_type, body in html_bodies: decoded_html = smart_str(body.decode()) email_body+=decoded_html additional_emails+=' ' + smart_str(mail_message.to) try: additional_emails+=' ' + smart_str(mail_message.bcc) except: pass try: additional_emails+=' ' + smart_str(mail_message.cc) except: pass re_emails = re.findall(r'[\w\.-]+@[\w\.-]+', email_body + additional_emails) emails = list(set(re_emails)) print 'emails' print emails for email in emails: generic_prop = ndb.GenericProperty() generic_prop._name = 'email' nodes = Node.query(generic_prop==email).fetch() if len(nodes)>0: for node in nodes: parents_edge_list = Edge.list( start_node = node.key, kind = 'parents' ) for edge in parents_edge_list['items']: parent_key = edge.end_node # insert a note related to the parent node note_author = Userinfo() note_author.display_name = user.google_display_name note_author.photo = user.google_public_profile_photo_url note = Note( owner = user.google_user_id, organization = user.organization, author = note_author, title = mail_message.subject, content = email_body ) entityKey_async = note.put_async() entityKey = entityKey_async.get_result() Edge.insert( start_node = parent_key, end_node = entityKey, kind = 'topics', inverse_edge = 'parents' ) EndpointsHelper.update_edge_indexes( parent_key=entityKey, kind='topics', indexed_edge=str(parent_key.id()) ) else: pass # We should create a lead related to this email # and attach this email with this lead else: print 'not authorized' else: print 'user doesnt exist'