comparison roundup/rest.py @ 5872:1b91e3df3fd0

Implement transitive props for sort and filter .. in REST API.
author Ralf Schlatterbeck <rsc@runtux.com>
date Mon, 26 Aug 2019 23:11:28 +0200
parents 5ae426616576
children 14f5c3179711
comparison
equal deleted inserted replaced
5871:acc4a128ab9b 5872:1b91e3df3fd0
683 ss = p[0] 683 ss = p[0]
684 else: 684 else:
685 ss = '+' 685 ss = '+'
686 pn = p 686 pn = p
687 # Only include properties where we have search permission 687 # Only include properties where we have search permission
688 # Note that hasSearchPermission already returns 0 for
689 # non-existing properties.
688 if self.db.security.hasSearchPermission( 690 if self.db.security.hasSearchPermission(
689 uid, class_name, pn 691 uid, class_name, pn
690 ): 692 ):
691 sort.append((ss, pn)) 693 sort.append((ss, pn))
692 elif key.startswith("@"): 694 elif key.startswith("@"):
693 # ignore any unsupported/previously handled control key 695 # ignore any unsupported/previously handled control key
694 # like @apiver 696 # like @apiver
695 pass 697 pass
696 else: # serve the filter purpose 698 else: # serve the filter purpose
699 p = key.split('.', 1)[0]
697 try: 700 try:
698 prop = class_obj.getprops()[key] 701 prop = class_obj.getprops()[p]
699 except KeyError: 702 except KeyError:
700 raise UsageError("Field %s is not valid for %s class."%( 703 raise UsageError("Field %s is not valid for %s class."%(
701 key, class_name)) 704 p, class_name))
702 # We drop properties without search permission silently 705 # We drop properties without search permission silently
703 # This reflects the current behavior of other roundup 706 # This reflects the current behavior of other roundup
704 # interfaces 707 # interfaces
708 # Note that hasSearchPermission already returns 0 for
709 # non-existing properties.
705 if not self.db.security.hasSearchPermission( 710 if not self.db.security.hasSearchPermission(
706 uid, class_name, key 711 uid, class_name, key
707 ): 712 ):
708 continue 713 continue
714
715 linkcls = class_obj
716 for p in key.split('.'):
717 prop = linkcls.getprops(protected = True)[p]
718 linkcls = getattr (prop, 'classname', None)
719 if linkcls:
720 linkcls = self.db.getclass(linkcls)
721
709 if isinstance (prop, (hyperdb.Link, hyperdb.Multilink)): 722 if isinstance (prop, (hyperdb.Link, hyperdb.Multilink)):
710 if key in filter_props: 723 if key in filter_props:
711 vals = filter_props[key] 724 vals = filter_props[key]
712 else: 725 else:
713 vals = [] 726 vals = []
714 linkcls = self.db.getclass (prop.classname)
715 for p in value.split(","): 727 for p in value.split(","):
716 if prop.try_id_parsing and p.isdigit(): 728 if prop.try_id_parsing and p.isdigit():
717 vals.append(p) 729 vals.append(p)
718 else: 730 else:
719 vals.append(linkcls.lookup(p)) 731 vals.append(linkcls.lookup(p))

Roundup Issue Tracker: http://roundup-tracker.org/