Add basic ownership as temporary prototype for demo #367
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a draft PR and not meant to merge. We have to work with a different system later to account for groups etc., this is a quick hack for the prototype.
What this does
With this PR, every asset uploaded to the metadata catalogue will have an associated user identifier that is considered the owner. This user identifier is the 'sub' token provided by keycloak. With this PR, users can only edit or delete assets they uploaded themselves. Attempting to edit or delete an asset created by a different user will result in an error. All assets are still public: user B can still see assets uploaded by user A.
How to test
Instructions assume default variables as defined in
.env
for credentials, etc.Updating the Database
This update requires a change to the database schema. No migration has been developed yet, so the easiest thing to do is to run the startup once with
--rebuild-db always
(if you do not care about the data in your local instance).Caution
Using
--rebuild-db always
will delete all data from the database. If you use it, make sure you do not care about the data.It is advised to turn off
--rebuild-db always
as soon as you do not need it anymore, to avoid unintended loss of data.If you care about the keeping the data in your database, you could just add the column yourself in mysql (UNTESTED):
However, I strongly recommend you do not test this feature on a database with data you care about.. Note that previous entries will no longer be editable by anyone through the REST API.
Create an Extra User
As the default config only ships with one predefined user, you'll need to create a second one:
localhost/aiod-auth
and enter admin credentials (admin/password)Users>add user
, give it some name.Try it in the REST API
You can now create an asset with your new user, and try to edit or delete it with the default user (or vice versa).
You should get an error when you try to edit a resource the user did not create.