Mercurial > hg > ChinaGisRestApi
comparison RestDbInterface.py @ 33:355b1fa2d78f
added meta permissions check
author | casties |
---|---|
date | Tue, 31 Aug 2010 14:20:24 +0200 |
parents | c732c2ff61d9 |
children | c237699c4752 |
comparison
equal
deleted
inserted
replaced
32:c732c2ff61d9 | 33:355b1fa2d78f |
---|---|
161 cur.close() | 161 cur.close() |
162 return {"fields":fields, "rows":data} | 162 return {"fields":fields, "rows":data} |
163 else: | 163 else: |
164 cur.close() | 164 cur.close() |
165 return None | 165 return None |
166 | |
167 def checkTableMetaPermission(self,action,schema,table,user=None): | |
168 """returns if the requested action on the table is allowed""" | |
169 logging.debug("checktablemetapermissions action=%s schema=%s table=%s user=%s"%(action,schema,table,user)) | |
170 if user is None: | |
171 user = self.REQUEST.get('AUTHENTICATED_USER',None) | |
172 logging.debug("user=%s"%user) | |
173 # TODO: what now? | |
174 return True | |
166 | 175 |
167 def setTableMetaTypes(self,schema,table,fields): | 176 def setTableMetaTypes(self,schema,table,fields): |
168 """sets the GIS meta information for table""" | 177 """sets the GIS meta information for table""" |
169 logging.debug("settablemetatypes schema=%s, table=%s, fields=%s"%(schema,table,fields)) | 178 logging.debug("settablemetatypes schema=%s, table=%s, fields=%s"%(schema,table,fields)) |
170 # TODO: what now? | 179 # TODO: what now? |
421 type = 'text' | 430 type = 'text' |
422 sqltype = 'text' | 431 sqltype = 'text' |
423 | 432 |
424 sqlFields.append({'name':name, 'type':type, 'sqltype':sqltype}) | 433 sqlFields.append({'name':name, 'type':type, 'sqltype':sqltype}) |
425 | 434 |
426 self.executeSQL('drop table if exists "%s"."%s"'%(schema,table),hasResult=False) | 435 if self.checkTableMetaPermission("create", schema, table): |
427 fieldString = ", ".join(['"%s" %s'%(f['name'],f['sqltype']) for f in sqlFields]) | 436 self.executeSQL('drop table if exists "%s"."%s"'%(schema,table),hasResult=False) |
428 sqlString = 'create table "%s"."%s" (%s)'%(schema,table,fieldString) | 437 fieldString = ", ".join(['"%s" %s'%(f['name'],f['sqltype']) for f in sqlFields]) |
429 logging.debug("createemptytable: SQL=%s"%sqlString) | 438 sqlString = 'create table "%s"."%s" (%s)'%(schema,table,fieldString) |
430 self.executeSQL(sqlString,hasResult=False) | 439 logging.debug("createemptytable: SQL=%s"%sqlString) |
431 self.setTableMetaTypes(schema,table,sqlFields) | 440 self.executeSQL(sqlString,hasResult=False) |
432 return sqlFields | 441 self.setTableMetaTypes(schema,table,sqlFields) |
442 return sqlFields | |
443 else: | |
444 logging.warning("create table not allowed!") | |
445 # throw exception? | |
446 return None | |
433 | 447 |
434 def createTableFromXML(self,schema,table,data, fields=None): | 448 def createTableFromXML(self,schema,table,data, fields=None): |
435 """create or replace a table with the given XML data""" | 449 """create or replace a table with the given XML data""" |
436 logging.debug("createTableFromXML schema=%s table=%s data=%s fields=%s"%(schema,table,data,fields)) | 450 logging.debug("createTableFromXML schema=%s table=%s data=%s fields=%s"%(schema,table,data,fields)) |
437 tablename = sqlName(table) | 451 tablename = sqlName(table) |