def resolve_relation_id(self, info, **kwargs): ret = None if sriutils.authorice_read_resource(info.context.user, self.handle_id): ret = getattr(self, 'relation_id', None) return ret
def resolve_relationship_object(instance, info, **kwargs): ret = None neo4jnode = self.get_inner_node(instance) relationship = getattr(neo4jnode, rel_method)() if relationship and rel_name in relationship: node = relationship[rel_name][0] relation_id = node['relationship_id'] handle_id = node['node'].data['handle_id'] authorized = False if sriutils.authorice_read_resource(info.context.user, handle_id): authorized = True else: authorized = not self.check_permissions if authorized: ret = NodeHandle.objects.get(handle_id=handle_id) # add relationship_id ret.relation_id = relation_id return ret
def resolve_match_txt(self, info, **kwargs): ret = None if sriutils.authorice_read_resource(info.context.user, self.handle_id): try: ret = getattr(self, 'match_txt', None) except: pass return ret
def resolve_description(self, info, **kwargs): ret = None if sriutils.authorice_read_resource(info.context.user, self.handle_id): try: ret = self.get_node().data.get("description") except: pass return ret
def resolve_with_same_name(self, info, **kwargs): ret = None if info.context and info.context.user.is_authenticated: ids_samename = self.get_node().with_same_name().get('ids', None) if ids_samename and len(self.get_node().with_same_name()) > 0: ret = [] for nh in NodeHandle.objects.filter( handle_id__in=ids_samename): if sriutils.authorice_read_resource(\ info.context.user, nh.handle_id): ret.append(nh) return ret
def resolve_relationship_list(instance, info, **kwargs): neo4jnode = self.get_inner_node(instance) relations = getattr(neo4jnode, rel_method)() nodes = relations.get(rel_name) id_list = [] if nodes: for node in nodes: relation_id = node['relationship_id'] node_elem = node['node'] # filter out nodes if self.filter: node_elem = self.filter(node_elem) # if we can get the label from the if filter_label: if filter_label not in node_elem.labels: node_elem = None if node_elem: node_id = node_elem.data.get('handle_id') if not relation_id: relation_id = -1 warnings.warn( "relationship_id is None".format(node), RuntimeWarning) id_list.append((node_id, relation_id)) id_list = sorted(id_list, key=lambda x: x[0]) ret = [] for handle_id, relation_id in id_list: nh = NodeHandle.objects.get(handle_id=handle_id) nh.relation_id = relation_id if sriutils.authorice_read_resource(info.context.user, nh.handle_id): ret.append(nh) # don't repeat objects on list if self.unique: ret = list(OrderedDict.fromkeys(ret)) return ret
def single_relation_resolver(info, node, method_name, relation_label): ret = None if info.context and info.context.user.is_authenticated: method = getattr(node, method_name) relation = method() if relation.get(relation_label): handle_id = relation[relation_label][0]['node'].handle_id relation_id = relation[relation_label][0]['relationship_id'] if handle_id and \ NodeHandle.objects.filter(handle_id=handle_id) and \ sriutils.authorice_read_resource(\ info.context.user, handle_id): ret = NodeHandle.objects.get(handle_id=handle_id) ret.relation_id = relation_id return ret
def test_read_resource(self): # check the read permissions over the contexts for the users result_read_ucm1 = sriutils.authorize_read_module( self.user1, self.community_ctxt) result_read_ucm2 = sriutils.authorize_read_module( self.user1, self.community_ctxt) result_read_ucm3 = sriutils.authorize_read_module( self.user1, self.community_ctxt) result_read_unt1 = sriutils.authorize_read_module( self.user2, self.network_ctxt) result_read_unt2 = sriutils.authorize_read_module( self.user2, self.network_ctxt) result_read_unt3 = sriutils.authorize_read_module( self.user2, self.network_ctxt) result_read_uct1 = sriutils.authorize_read_module( self.user3, self.contracts_ctxt) result_read_uct2 = sriutils.authorize_read_module( self.user3, self.contracts_ctxt) result_read_uct3 = sriutils.authorize_read_module( self.user3, self.contracts_ctxt) self.assertTrue(result_read_ucm1) self.assertTrue(result_read_ucm2) self.assertTrue(result_read_ucm3) self.assertTrue(result_read_unt1) self.assertTrue(result_read_unt2) self.assertTrue(result_read_unt3) self.assertTrue(result_read_uct1) self.assertTrue(result_read_uct2) self.assertTrue(result_read_uct3) # check if the three users can read the organization1 result_auth_u1 = sriutils.authorice_read_resource( self.user1, self.organization1.handle_id) result_auth_u2 = sriutils.authorice_read_resource( self.user2, self.organization1.handle_id) result_auth_u3 = sriutils.authorice_read_resource( self.user3, self.organization1.handle_id) self.assertTrue(result_auth_u1) self.assertTrue(result_auth_u2) self.assertTrue(result_auth_u3) # check if the three users can read the organization2 result_auth_u1 = sriutils.authorice_read_resource( self.user1, self.organization2.handle_id) result_auth_u2 = sriutils.authorice_read_resource( self.user2, self.organization2.handle_id) result_auth_u3 = sriutils.authorice_read_resource( self.user3, self.organization2.handle_id) self.assertTrue(result_auth_u1) self.assertTrue(result_auth_u2) self.assertTrue(result_auth_u3) # check if the three users can read the contact1 result_auth_u1 = sriutils.authorice_read_resource( self.user1, self.contact1.handle_id) result_auth_u2 = sriutils.authorice_read_resource( self.user2, self.contact1.handle_id) result_auth_u3 = sriutils.authorice_read_resource( self.user3, self.contact1.handle_id) self.assertTrue(result_auth_u1) self.assertTrue(result_auth_u2) self.assertTrue(result_auth_u3) # check if the three users can read the contact2 result_auth_u1 = sriutils.authorice_read_resource( self.user1, self.contact2.handle_id) result_auth_u2 = sriutils.authorice_read_resource( self.user2, self.contact2.handle_id) result_auth_u3 = sriutils.authorice_read_resource( self.user3, self.contact2.handle_id) self.assertTrue(result_auth_u1) self.assertTrue(result_auth_u2) self.assertTrue(result_auth_u3)