diff --git a/package-lock.json b/package-lock.json index 693eab29b..bf5caf0f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1895,29 +1895,11 @@ "integrity": "sha512-wMHVg2EOHaMRxbzgFJ9gtjOOCrI80OHLG14rxi28XwOW8ux6IiEbRCGGGqCtdAIg4FQCbW20k9RsT4y3gJlFug==" }, "axios": { - "version": "0.19.2", - "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", - "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", + "version": "0.21.1", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", + "integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", "requires": { - "follow-redirects": "1.5.10" - }, - "dependencies": { - "debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "requires": { - "ms": "2.0.0" - } - }, - "follow-redirects": { - "version": "1.5.10", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", - "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", - "requires": { - "debug": "=3.1.0" - } - } + "follow-redirects": "^1.10.0" } }, "babel-code-frame": { @@ -4472,8 +4454,7 @@ "follow-redirects": { "version": "1.12.1", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.12.1.tgz", - "integrity": "sha512-tmRv0AVuR7ZyouUHLeNSiO6pqulF7dYa3s19c6t+wz9LD69/uSzdMxJ2S91nTI9U3rt/IldxpzMOFejp6f0hjg==", - "dev": true + "integrity": "sha512-tmRv0AVuR7ZyouUHLeNSiO6pqulF7dYa3s19c6t+wz9LD69/uSzdMxJ2S91nTI9U3rt/IldxpzMOFejp6f0hjg==" }, "for-in": { "version": "1.0.2", @@ -4751,12 +4732,6 @@ "dev": true, "optional": true }, - "ini": { - "version": "1.3.5", - "bundled": true, - "dev": true, - "optional": true - }, "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, @@ -5785,9 +5760,15 @@ "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "ini": { +<<<<<<< HEAD "version": "1.3.8", "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.8.tgz", "integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==", +======= + "version": "1.3.7", + "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.7.tgz", + "integrity": "sha512-iKpRpXP+CrP2jyrxvg1kMUpXDyRUFDWurxbnVT1vQPx+Wz9uCYsMIqYuSBLV+PAaZG/d7kRLKRFc9oDMsH+mFQ==", +>>>>>>> develop "dev": true }, "inquirer": { @@ -6846,7 +6827,8 @@ "ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", + "dev": true }, "multicast-dns": { "version": "6.2.3", diff --git a/package.json b/package.json index bbc47d128..0227f7253 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "build-prod": "cross-env NODE_ENV=production webpack --config webpack.prod.js --display-error-details --progress --hide-modules" }, "dependencies": { - "axios": "^0.19.2", "blurhash": "^1.1.3", + "axios": "^0.21.1", "buefy": "^0.9.4", "bulma": "^0.9.1", "css-vars-ponyfill": "^2.3.1", diff --git a/src/assets/css/tainacan-media-page.css b/src/assets/css/tainacan-media-page.css new file mode 100644 index 000000000..32c009785 --- /dev/null +++ b/src/assets/css/tainacan-media-page.css @@ -0,0 +1,36 @@ +body:not([class]){ + margin: auto; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; +} +body:not([class]) > img { + width: auto; +} +body:not([class]) > iframe { + width: 100%; + height: 100%; + min-height: 80vh; + border: none; +} +body:not([class]) > audio, +body:not([class]) > video { + width: 100%; + height: auto; + min-height: 54px; + max-height: 100%; +} +body:not([class]) > audio { + width: 100%; +} +body:not([class]) > a, +body:not([class]) > p { + z-index: 99; + padding: 1rem 4.33337vw; + background: white; + border-radius: 3px; + word-wrap: break-word; +} \ No newline at end of file diff --git a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php index d3018f359..3345e4471 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php @@ -145,7 +145,7 @@ class REST_Items_Controller extends REST_Controller { ) ); register_rest_route( - $this->namespace, '/collection/(?P[\d]+)/' . $this->rest_base . '/submission/(?P[\d]+)/finish', + $this->namespace, '/collection/(?P[\d]+)/' . $this->rest_base . '/submission/(?P[a-z0-9]+)/finish', array( array( 'methods' => \WP_REST_Server::CREATABLE, @@ -987,12 +987,16 @@ class REST_Items_Controller extends REST_Controller { if ($item->validate()) { $item = $this->items_repository->insert( $item ); - $fake_id = \hexdec(\uniqid()); + $fake_id = md5(uniqid(mt_rand(), true)); $id = $item->get_id(); - set_transient('tnc_transient_submission_' . $fake_id, $id, 300); - $response_item = $this->prepare_item_for_response($item, $request); - $response_item['id'] = $fake_id; - return new \WP_REST_Response($response_item, 201 ); + if (set_transient('tnc_transient_submission_' . $fake_id, $id, 300) == true) { + $response_item = $this->prepare_item_for_response($item, $request); + $response_item['id'] = $fake_id; + return new \WP_REST_Response($response_item, 201 ); + } else return new \WP_REST_Response([ + 'error_message' => __('unable create submission ID.', 'tainacan'), + ], 400); + } else { return new \WP_REST_Response([ 'error_message' => __('One or more values are invalid.', 'tainacan'), diff --git a/src/classes/api/endpoints/class-tainacan-rest-roles-controller.php b/src/classes/api/endpoints/class-tainacan-rest-roles-controller.php index 5bd3ca306..0014e9647 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-roles-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-roles-controller.php @@ -151,6 +151,7 @@ class REST_Roles_Controller extends REST_Controller { if ( isset($request['capabilities']) && is_array($request['capabilities']) ) { $this->handle_capabilities_for_role($role_slug, $request['capabilities']); + $this->handle_capabilites_default_for_role($role_slug); } if ($new_role instanceof \WP_Role) { @@ -262,6 +263,7 @@ class REST_Roles_Controller extends REST_Controller { if ( is_array($request['capabilities']) ) { $this->handle_capabilities_for_role($role_slug, $request['capabilities']); + $this->handle_capabilites_default_for_role($role_slug); } elseif ( isset($request['add_cap']) ) { // validate that we only deal with tainacan capabilities @@ -317,6 +319,13 @@ class REST_Roles_Controller extends REST_Controller { } + private function handle_capabilites_default_for_role($role_slug) { + if ( !isset( \wp_roles()->roles[$role_slug] ) ) { + return false; + } + \wp_roles()->add_cap($role_slug, 'read', true); + } + /** * @param \WP_REST_Request $request * diff --git a/src/classes/class-tainacan-media.php b/src/classes/class-tainacan-media.php index c331afeb9..8810fd651 100644 --- a/src/classes/class-tainacan-media.php +++ b/src/classes/class-tainacan-media.php @@ -21,6 +21,9 @@ class Media { protected function __construct() { add_action( 'init', [$this, 'add_attachment_page_rewrite_rule'] ); + add_action( 'admin_enqueue_scripts', array( &$this, 'add_css' ) ); + add_action( 'wp_enqueue_scripts', array( &$this, 'add_css' ) ); + add_filter( 'query_vars', [$this, 'attachment_page_add_var'] ); add_action( 'template_redirect', [$this, 'attachment_page'] ); } @@ -33,6 +36,11 @@ class Media { ); } + public function add_css() { + global $TAINACAN_BASE_URL; + wp_enqueue_style( 'tainacan-media-page', $TAINACAN_BASE_URL . '/assets/css/tainacan-media-page.css', [], TAINACAN_VERSION ); + } + public function attachment_page_add_var($vars) { $vars[] = 'tainacan_attachment_page'; return $vars; @@ -320,11 +328,11 @@ class Media { public function attachment_page() { $att_id = get_query_var('tainacan_attachment_page'); - + if ( ! $att_id ) { return; // continue normal execution } - + $attachment = get_post($att_id); if ( $attachment instanceof \WP_Post && $attachment->post_type == 'attachment' ) { @@ -359,7 +367,7 @@ class Media { $output .= $img; } else { - + wp_print_styles('tainacan-media-page'); global $wp_embed; $url = wp_get_attachment_url($att_id); diff --git a/src/classes/class-tainacan-roles.php b/src/classes/class-tainacan-roles.php index f3882427a..dbe5d01e5 100644 --- a/src/classes/class-tainacan-roles.php +++ b/src/classes/class-tainacan-roles.php @@ -24,6 +24,9 @@ class Roles { */ private function __construct() { + $this->meta_caps = (new \Tainacan\Entities\Metadatum())->get_capabilities(); + $this->filters_caps = (new \Tainacan\Entities\Filter())->get_capabilities(); + $this->capabilities = [ 'manage_tainacan' => [ 'display_name' => __('Manage Tainacan', 'tainacan'), @@ -172,6 +175,10 @@ class Roles { 'display_name' => __('Manage Collection', 'tainacan'), 'description' => __('Manage all collection settings, items, metadata, filters, etc.', 'tainacan'), 'scope' => 'collection', + 'dependencies' => [ + $this->meta_caps->read_private_posts, + $this->filters_caps->read_private_posts + ], 'supercaps' => [ 'manage_tainacan', 'manage_tainacan_collection_all' @@ -247,6 +254,9 @@ class Roles { 'display_name' => __('View private metadata', 'tainacan'), 'description' => __('Access private metadata in this collection', 'tainacan'), 'scope' => 'collection', + 'dependencies' => [ + $this->meta_caps->read_private_posts, // e.g.: 'read_private_tainacan-metadata' + ], 'supercaps' => [ 'manage_tainacan', 'manage_tainacan_collection_all', @@ -258,6 +268,9 @@ class Roles { 'display_name' => __('View private filters', 'tainacan'), 'description' => __('Access private filters in this collection', 'tainacan'), 'scope' => 'collection', + 'dependencies' => [ + $this->filters_caps->read_private_posts, // e.g.: 'read_private_tainacan-filters' + ], 'supercaps' => [ 'manage_tainacan', 'manage_tainacan_collection_all', @@ -392,7 +405,8 @@ class Roles { 'slug' => 'tainacan-administrator', 'display_name' => 'Tainacan Administrator', 'caps' => [ - 'manage_tainacan' => true + 'manage_tainacan' => true, + 'read' => true ] ], 'tainacan-editor' => [ @@ -414,7 +428,8 @@ class Roles { 'tnc_rep_read_private_metadata' => true, 'tnc_rep_read_private_filters' => true, 'tnc_rep_read_logs' => true, - 'manage_tainacan_collection_all' => true + 'manage_tainacan_collection_all' => true, + 'read' => true ] ], 'tainacan-author' => [ @@ -427,6 +442,7 @@ class Roles { 'tnc_rep_read_private_taxonomies' => true, 'tnc_rep_read_private_metadata' => true, 'tnc_rep_read_private_filters' => true, + 'read' => true ] ], ]; @@ -534,6 +550,17 @@ class Roles { continue; } + if( in_array($requested_cap, [ + $this->meta_caps->read_private_posts, + $this->filters_caps->read_private_posts] + ) && ( + $user->has_cap('manage_tainacan') || + $user->has_cap('manage_tainacan_collection_all') + ) + ) { + $allcaps = array_merge($allcaps, [ $requested_cap => true ]); + } + if ( \strpos($cap, 'tnc_') === 0 ) { if ( $user->has_cap('manage_tainacan') ) { diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index 09bed6e5c..95c1ccf5f 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -544,6 +544,8 @@ class Item extends Entity { * * @type bool $hide_empty Wether to hide or not metadata the item has no value to * Default: true + * @type bool $display_slug_as_class Show metadata slug as a class in the div before the metadata block + * Default: false * @type string $before String to be added before each metadata block * Default '