1+ from typing import Optional
2+ from ckan .types import (
3+ AuthFunction ,
4+ Context ,
5+ DataDict ,
6+ AuthResult
7+ )
8+
19from ckan .plugins .toolkit import chained_auth_function , h , _
2- from ckan .model .group import Group
3- from ckanapi import LocalCKAN , ValidationError
410
511
612@chained_auth_function
7- def package_update (up_func , context , data_dict ):
13+ def package_update (up_func : AuthFunction ,
14+ context : Context ,
15+ data_dict : Optional [DataDict ]) -> AuthResult :
816 """
917 Recombinant packages and resources should not be
1018 editable by users after they have been made.
1119
1220 Affects update, patch, and delete.
1321 """
14- if data_dict and data_dict .get (u 'type' ) in h .recombinant_get_types ():
22+ if data_dict and data_dict .get ('type' ) in h .recombinant_get_types ():
1523 return {'success' : False ,
1624 'msg' : _ ('User %s not authorized to modify Recombinant type: %s' ) %
17- (str (context [u'user' ]), data_dict .get (u'type' ))}
18- return up_func (context , data_dict )
25+ (str (context ['user' ]), data_dict .get ('type' ))}
26+ # type_ignore_reason: incomplete typing
27+ return up_func (context , data_dict ) # type: ignore
1928
2029
2130@chained_auth_function
22- def package_create (up_func , context , data_dict ):
31+ def package_create (up_func : AuthFunction ,
32+ context : Context ,
33+ data_dict : Optional [DataDict ]) -> AuthResult :
2334 """
2435 If the user has permissions to create packages, they should still
2536 be allowed to create the Recombinant packages and resources.
2637
2738 However, users should not be allowed to create multiple packages
2839 of the same type for a single organization.
2940 """
30- if data_dict and data_dict .get (u 'type' ) in h .recombinant_get_types ():
41+ if data_dict and data_dict .get ('type' ) in h .recombinant_get_types ():
3142 return {'success' : False ,
32- 'msg' : _ ('User %s not authorized to create Recombinant packages: %s' ) %
33- (str (context [u'user' ]), data_dict .get (u'type' ))}
34- return up_func (context , data_dict )
43+ 'msg' : _ ('User %s not authorized to create '
44+ 'Recombinant packages: %s' ) %
45+ (str (context ['user' ]), data_dict .get ('type' ))}
46+ # type_ignore_reason: incomplete typing
47+ return up_func (context , data_dict ) # type: ignore
3548
3649
3750@chained_auth_function
38- def datastore_delete (up_func , context , data_dict ):
51+ def datastore_delete (up_func : AuthFunction ,
52+ context : Context ,
53+ data_dict : Optional [DataDict ]) -> AuthResult :
3954 """
4055 Users should not be able to delete a Datestore table for
4156 Recombinant types. We only want them to be able to delete rows.
4257 """
43- res = context ['model' ].Resource .get (data_dict .get ('resource_id' ))
58+ if not data_dict :
59+ data_dict = {}
60+ res = context ['model' ].Resource .get (data_dict .get ('resource_id' , '' ))
4461 pkg = context ['model' ].Package .get (getattr (res , 'package_id' , None ))
4562 if not res or not pkg or pkg .type not in h .recombinant_get_types ():
4663 return up_func (context , data_dict )
@@ -49,6 +66,5 @@ def datastore_delete(up_func, context, data_dict):
4966 # we do not want that to happen for Recombinant types.
5067 return {'success' : False ,
5168 'msg' : _ ("Cannot delete Datastore for type: %s. "
52- "Use datastore_records_delete instead." )
53- % pkg .type }
69+ "Use datastore_records_delete instead." ) % pkg .type }
5470 return up_func (context , data_dict )
0 commit comments