@@ -695,12 +695,24 @@ def list(cls, gl, **kwargs):
695695
696696 return gl .list (cls , ** kwargs )
697697
698+ @classmethod
699+ def get (cls , gl , id , ** kwargs ):
700+ if cls .canGet is True :
701+ return cls (gl , id , ** kwargs )
702+ elif cls .canGet == 'from_list' :
703+ for obj in cls .list (gl , ** kwargs ):
704+ obj_id = getattr (obj , obj .idAttr )
705+ if str (obj_id ) == str (id ):
706+ return obj
707+
708+ raise GitlabGetError ("Object not found" )
709+
698710 @classmethod
699711 def _get_list_or_object (cls , gl , id , ** kwargs ):
700712 if id is None and cls .getListWhenNoId :
701713 return cls .list (gl , ** kwargs )
702714 else :
703- return cls (gl , id , ** kwargs )
715+ return cls . get (gl , id , ** kwargs )
704716
705717 def _get_object (self , k , v ):
706718 if self ._constructorTypes and k in self ._constructorTypes :
@@ -834,7 +846,7 @@ def json(self):
834846
835847class UserKey (GitlabObject ):
836848 _url = '/users/%(user_id)s/keys'
837- canGet = False
849+ canGet = 'from_list'
838850 canUpdate = False
839851 requiredUrlAttrs = ['user_id' ]
840852 requiredCreateAttrs = ['title' , 'key' ]
@@ -882,7 +894,7 @@ def Key(self, id=None, **kwargs):
882894
883895class GroupMember (GitlabObject ):
884896 _url = '/groups/%(group_id)s/members'
885- canGet = False
897+ canGet = 'from_list'
886898 requiredUrlAttrs = ['group_id' ]
887899 requiredCreateAttrs = ['access_level' , 'user_id' ]
888900 requiredUpdateAttrs = ['access_level' ]
@@ -928,7 +940,7 @@ class Issue(GitlabObject):
928940 _url = '/issues'
929941 _constructorTypes = {'author' : 'User' , 'assignee' : 'User' ,
930942 'milestone' : 'ProjectMilestone' }
931- canGet = False
943+ canGet = 'from_list'
932944 canDelete = False
933945 canUpdate = False
934946 canCreate = False
@@ -997,7 +1009,7 @@ class ProjectKey(GitlabObject):
9971009
9981010class ProjectEvent (GitlabObject ):
9991011 _url = '/projects/%(project_id)s/events'
1000- canGet = False
1012+ canGet = 'from_list'
10011013 canDelete = False
10021014 canUpdate = False
10031015 canCreate = False
@@ -1073,7 +1085,7 @@ class ProjectNote(GitlabObject):
10731085class ProjectTag (GitlabObject ):
10741086 _url = '/projects/%(project_id)s/repository/tags'
10751087 idAttr = 'name'
1076- canGet = False
1088+ canGet = 'from_list'
10771089 canDelete = False
10781090 canUpdate = False
10791091 requiredUrlAttrs = ['project_id' ]
0 commit comments