It made no sense to have a file upload in each form that needs a media, because to reuse an existing media users would need to upload the exact same file again; this is very unusual and unfriendly. A better option is to have a “centralized” media section, where people can upload files there, and then have a picker to select from there. Ideally, there would be an upload option in the picker, but i did not add it yet. I’ve split the content from the media because i want users to have the option to update a media, for instance when they need to upload a reduced or cropped version of the same photo, without an edit they would need to upload the file as a new media and then update all places where the old version was used. And i did not want to trouble people that uploads the same photo twice: without the separate relation, doing so would throw a constraint error. I do not believe there is any security problem to have all companies link their media to the same file, as they were already readable by everyone and could upload the data from a different company to their own; in other words, it is not worse than it was now.
60 lines
1.9 KiB
PL/PgSQL
60 lines
1.9 KiB
PL/PgSQL
-- Test media_content
|
|
set client_min_messages to warning;
|
|
create extension if not exists pgtap;
|
|
reset client_min_messages;
|
|
|
|
begin;
|
|
|
|
select plan(21);
|
|
|
|
set search_path to camper, public;
|
|
|
|
select has_table('media_content');
|
|
select has_pk('media_content');
|
|
select table_privs_are('media_content', 'guest', array['SELECT']);
|
|
select table_privs_are('media_content', 'employee', array['SELECT']);
|
|
select table_privs_are('media_content', 'admin', array['SELECT', 'INSERT', 'UPDATE', 'DELETE']);
|
|
select table_privs_are('media_content', 'authenticator', array[]::text[]);
|
|
|
|
select has_column('media_content', 'content_hash');
|
|
select col_is_pk('media_content', 'content_hash');
|
|
select col_type_is('media_content', 'content_hash', 'bytea');
|
|
select col_not_null('media_content', 'content_hash');
|
|
select col_has_default('media_content', 'content_hash');
|
|
select col_default_is('media_content', 'content_hash', 'sha256(bytes)');
|
|
|
|
select has_column('media_content', 'media_type');
|
|
select col_type_is('media_content', 'media_type', 'media_type');
|
|
select col_not_null('media_content', 'media_type');
|
|
select col_hasnt_default('media_content', 'media_type');
|
|
|
|
select has_column('media_content', 'bytes');
|
|
select col_type_is('media_content', 'bytes', 'bytea');
|
|
select col_not_null('media_content', 'bytes');
|
|
select col_hasnt_default('media_content', 'bytes');
|
|
|
|
|
|
set client_min_messages to warning;
|
|
truncate media_content cascade;
|
|
reset client_min_messages;
|
|
|
|
insert into media_content (media_type, bytes)
|
|
values ('text/plain', 'content2')
|
|
, ('text/plain', 'content4')
|
|
;
|
|
|
|
select bag_eq(
|
|
$$ select encode(content_hash, 'hex'), convert_from(bytes, 'utf-8') from media_content $$,
|
|
$$ values ('dab741b6289e7dccc1ed42330cae1accc2b755ce8079c2cd5d4b5366c9f769a6', 'content2')
|
|
, ('b04813d4f04a27cbd8a5d7828344a0c7d206a486343f503cb7e3d53e1d8e95a0', 'content4')
|
|
$$,
|
|
'Should automatically compute the content_hash'
|
|
);
|
|
|
|
|
|
select *
|
|
from finish();
|
|
|
|
rollback;
|
|
|