6

I have created a centralized database using PostgreSQL and created multiple users assigned with different roles i.e. SELECT, UPDATE, MODIFY and DELETE etc.

Example:

CREATE USER hasan WITH PASSWORD 'hasan'

GRANT SELECT ON pois TO hasan

For user 'hasan' I have granted SELECT privileges on the pois table which means he can only select and view the data. It works perfectly both in PostgreSQL and QGIS environment. The user can only run select query on the table and view the data in QGIS environment and cannot update or delete any record as I expected.

But the problem is in the QGIS environment, when the user right click on the table, he can easily export the table into a shapefile and then edit or update whatever he wants to do.

What can I do to stop the user from exporting the PostGIS table to a shapefile in QGIS?

0

3 Answers 3

17

Once you allow a user to select the data from your database there is no way to prevent them doing what they like with the data. If it is important to you that the user can only view and not edit the data you could consider using a WMS server (e.g GeoServer, MapServer) to render the data on your server and send only an image of the rendered data to the user.

3
  • Thank you for your quick response. I cannot do what you are suggesting because there are some users who will have the privileges to edit and update the data. Jul 28, 2016 at 8:09
  • 5
    you can allow those users to access the data through a WFS
    – Ian Turton
    Jul 28, 2016 at 8:10
  • 1
    WMS is perfect for this use case. Jul 29, 2016 at 11:48
8

Some time ago I had the same challenge. What I did was remove the button export to the interface qgis to users who didn't have a permission.

How to? I leave some tips... QGis interface uses the system registry for show or not show some elements as buttons, windows, labels, etc.

You have a create a stand alone app that run at startup of QGIS and you connect to your database to read the user's permissions and finally edit the system registry. You can append the execute on "\bin\qgis.bat"

  1. In QGis go to Configuration > customization > enable custom for all.
  2. Edit the system registry: hkey_current_user/Software/QGIS/CUSTOMIZATION/QgsVectorLayerSaveAsDialogBase/buttonBox set to false.
  3. The results is the widget export shape without accept button. The button accept has removed
2
  • that's a good one but i cannot do that because my server runs on a public ip address and anyone who have username and password to my database can access it at home and do the same thing. Jul 29, 2016 at 5:36
  • You could configure remote access from pg_hba.conf file and only allow access from place work(?)
    – d345k0
    Jul 29, 2016 at 14:37
0

I wonder why you bother with this. Even if anyone loads your data as shapefile he/she is not able to modify your primary data-source (the database), it is just a copy. He/she can do everything of his premises with this data once it is fully copied to the users computer- no way to limit this, but why should you?

Even if there were a way in QGIS, a user could easily export to shapefile using any different converter-tool (e.g. pgsql2shp). Alternativly he could just post an SQL-query against your database and get the data directly.

Having said this all you really have to care about is that your database-roles are configured appropriately enabling only those users update-operations you want. So if you're concerend about your data, just disable accessing it. For instance grant access only to the members within your organization.

Compare this with users viewing the sourcecode of your website on the internet. There's no way to prevent this from happening, you could make it harder, yes, but that's it. The same applies to making a screenshot of your app or whatever.

4
  • 2
    So it's okay to have users copying data and making their own changes that are never incorporated into the main database? That is a YUGE problem I encounter on an almost daily basis. Jul 28, 2016 at 16:29
  • 1
    my company do not allow anyone to copy the data because its not for free Jul 29, 2016 at 5:25
  • But you can´t hinder anyone copying it if he can view the data. Think of taking a screenshot from a website. If you can access the site you can also copy its content, no way to avoid this. SQL - and this is what users may use when accessing your data, not neccessarily QGIS - does not make any difference on viewing data and copying it. Jul 29, 2016 at 7:12
  • 1
    @DenaliHardtail if it is important that the user update are incorporated in the database that mean these user are producing meaningful/trustful update and if so why not grant the update privilege ? it seem to be more an update process problem than an allowing copy problem...
    – J.R
    Oct 13, 2022 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.