Browse Source

updated uuid

Bachir Soussi Chiadmi 5 years ago
parent
commit
0615369680

+ 1 - 0
sites/all/modules/contrib/admin/uuid/uuid.features.inc

@@ -168,6 +168,7 @@ function uuid_entities_rebuild($module_name = '', $op = 'rebuild') {
     foreach ($entities as $plan_name => $entities) {
       // Let other modules do things before default entities are created.
       module_invoke_all("uuid_entities_pre_$op", $plan_name);
+      drupal_alter("uuid_entities_pre_$op", $entities, $plan_name);
       foreach ($entities as $entity) {
         entity_uuid_save($entity->__metadata['type'], $entity);
       }

+ 3 - 4
sites/all/modules/contrib/admin/uuid/uuid.info

@@ -7,9 +7,8 @@ files[] = uuid.test
 dependencies[] = node
 dependencies[] = user
 
-; Information added by Drupal.org packaging script on 2017-04-27
-version = "7.x-1.0"
+; Information added by Drupal.org packaging script on 2018-07-19
+version = "7.x-1.2"
 core = "7.x"
 project = "uuid"
-datestamp = "1493291958"
-
+datestamp = "1531990689"

+ 3 - 4
sites/all/modules/contrib/admin/uuid/uuid_path/uuid_path.info

@@ -5,9 +5,8 @@ package = UUID
 dependencies[] = uuid
 
 
-; Information added by Drupal.org packaging script on 2017-04-27
-version = "7.x-1.0"
+; Information added by Drupal.org packaging script on 2018-07-19
+version = "7.x-1.2"
 core = "7.x"
 project = "uuid"
-datestamp = "1493291958"
-
+datestamp = "1531990689"

+ 8 - 0
sites/all/modules/contrib/admin/uuid/uuid_services/uuid_services.admin.inc

@@ -18,5 +18,13 @@ function uuid_services_settings() {
     '#description' => t('Check this box to automatically provide Services integration for all entity types with UUID support.'),
     '#default_value' => variable_get('uuid_services_support_all_entity_types', FALSE),
   );
+  $form['uuid_services_allowed_media_mimes'] = array(
+    '#type' => 'textarea',
+    '#title' => t('Allowed Media Mime type'),
+    '#default_value' => variable_get('uuid_services_allowed_media_mimes', UUID_SERVICES_DEFAULT_ALLOWED_MEDIA_MIMES),
+    '#cols' => 40,
+    '#rows' => 5,
+    '#description' => t("Enter one mime type per line you wish to allow in the system without extension. Example mime type '<em>video/brightcove</em>'."),
+  );
   return system_settings_form($form);
 }

+ 150 - 0
sites/all/modules/contrib/admin/uuid/uuid_services/uuid_services.file_services.test

@@ -0,0 +1,150 @@
+<?php
+
+/**
+ * @file
+ * Test the UUID File Services integration.
+ */
+
+ /**
+  * Test the UUID File Services integration.
+  */
+class UuidFileServicesTest extends ServicesWebTestCase {
+
+  protected $priviledgedUser = NULL;
+
+  protected $endpoint = NULL;
+
+  /**
+   * Implementation of getInfo().
+   */
+  public static function getInfo() {
+    return array(
+      'name' => 'UUID File Services tests',
+      'description' => 'Test the file services resource UUID methods and actions.',
+      'group' => 'UUID',
+    );
+  }
+
+  /**
+   * Implementation of setUp().
+   */
+  public function setUp() {
+    parent::setUp(
+      'ctools',
+      'services',
+      'rest_server',
+      'uuid_services',
+      'entity',
+      'file',
+      'field',
+      'file_entity'
+    );
+    $this->endpoint = $this->saveNewEndpoint();
+
+    variable_set('file_entity_default_allowed_extensions', 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps ppsx odt ods odp mp3 mov mp4 m4a m4v mpeg avi ogg oga ogv weba webp webm');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function saveNewEndpoint() {
+    $edit = $this->populateEndpointFAPI();
+    $endpoint = new stdClass();
+    $endpoint->disabled = FALSE;
+    $endpoint->api_version = 3;
+    $endpoint->name = $edit['name'];
+    $endpoint->server = $edit['server'];
+    $endpoint->path = $edit['path'];
+    $endpoint->authentication = array(
+      'services' => 'services',
+    );
+    $endpoint->server_settings = array(
+      'formatters' => array(
+        'json' => TRUE,
+        'bencode' => TRUE,
+        'rss' => TRUE,
+        'plist' => TRUE,
+        'xmlplist' => TRUE,
+        'php' => TRUE,
+        'yaml' => TRUE,
+        'jsonp' => FALSE,
+        'xml' => FALSE,
+      ),
+      'parsers' => array(
+        'application/x-yaml' => TRUE,
+        'application/json' => TRUE,
+        'application/vnd.php.serialized' => TRUE,
+        'application/plist' => TRUE,
+        'application/plist+xml' => TRUE,
+        'application/x-www-form-urlencoded' => TRUE,
+        'multipart/form-data' => TRUE,
+      ),
+    );
+    $endpoint->resources = array(
+      'file' => array(
+        'operations' => array(
+          'retrieve' => array(
+            'enabled' => '1',
+          ),
+          'delete' => array(
+            'enabled' => '1',
+          ),
+          'index' => array(
+            'enabled' => '1',
+          ),
+          'update' => array(
+            'enabled' => '1',
+          ),
+        ),
+        'actions' => array(
+          'create_raw' => array(
+            'enabled' => '1',
+          ),
+        ),
+      ),
+    );
+    $endpoint->debug = 1;
+    $endpoint->export_type = FALSE;
+    services_endpoint_save($endpoint);
+    $endpoint = services_endpoint_load($endpoint->name);
+    $this->assertTrue($endpoint->name == $edit['name'], 'Endpoint successfully created');
+    return $endpoint;
+  }
+
+  /**
+   * Tests file creation.
+   */
+  public function testFileUpdate() {
+    $this->privilegedUser = $this->drupalCreateUser(array('create files'));
+    $this->drupalLogin($this->privilegedUser);
+
+    // Get a test file.
+    $testfiles = $this->drupalGetTestFiles('php');
+    $testfile = current($testfiles);
+
+    // Setup file to be created.
+    $filepath = file_default_scheme() . '://' . rand() . '/' . rand() . '/' . $testfile->filename;
+    $file_data = array(
+      'uid' => '0',
+      'filesize' => filesize($testfile->uri),
+      'filename' => $testfile->filename,
+      'filepath' => $filepath,
+      'file' => base64_encode(file_get_contents($testfile->uri)),
+      'uuid' => 'ee26fe5d-f781-4a38-bfe0-8bb350b90073',
+      'type' => 'image',
+      'filemime' => 'text/plain',
+      'uri' => $testfile->uri,
+    );
+
+    $response = $this->servicesPut($this->endpoint->path . '/file/create', $file_data);
+
+    // Get the saved file's extension.
+    $file = file_load($response['body']->fid);
+    $name = explode('.', $file->filename);
+    $last = array_pop($name);
+    $extension = strtolower($last);
+
+    $this->assertNotEqual('php', $extension, 'File was not created with a "php" extension.', 'UUID: File Create');
+  }
+
+}

+ 9 - 4
sites/all/modules/contrib/admin/uuid/uuid_services/uuid_services.info

@@ -7,9 +7,14 @@ dependencies[] = services
 dependencies[] = uuid
 dependencies[] = entity
 
-; Information added by Drupal.org packaging script on 2017-04-27
-version = "7.x-1.0"
+test_dependencies[] = services
+test_dependencies[] = entity
+test_dependencies[] = file
+test_dependencies[] = field
+test_dependencies[] = file_entity
+
+; Information added by Drupal.org packaging script on 2018-07-19
+version = "7.x-1.2"
 core = "7.x"
 project = "uuid"
-datestamp = "1493291958"
-
+datestamp = "1531990689"

+ 14 - 0
sites/all/modules/contrib/admin/uuid/uuid_services/uuid_services.install

@@ -0,0 +1,14 @@
+<?php
+
+/**
+ * @file
+ * UUID module installation functions.
+ */
+
+/**
+ * Implements hook_uninstall().
+ */
+function uuid_services_uninstall() {
+  variable_del('uuid_services_support_all_entity_types');
+  variable_del('uuid_services_allowed_media_mimes');
+}

+ 23 - 0
sites/all/modules/contrib/admin/uuid/uuid_services/uuid_services.module

@@ -5,6 +5,14 @@
  * UUID Services module functions.
  */
 
+/**
+ * Defines defaults for UUID_SERVICES_ALLOWED_MEDIA_MIMES.
+ */
+define('UUID_SERVICES_DEFAULT_ALLOWED_MEDIA_MIMES',
+'video/brightcove
+video/youtube'
+);
+
 /**
  * Implements hook_menu().
  */
@@ -147,6 +155,21 @@ function _uuid_services_entity_update($entity_type, $uuid, $entity) {
       $entity = (object) $entity;
     }
     $entity->uuid_services = TRUE;
+    // Check that the mime type is whitelisted.
+    $valid_media_mimes = variable_get('uuid_services_allowed_media_mimes', UUID_SERVICES_DEFAULT_ALLOWED_MEDIA_MIMES);
+
+    // Sanitize file user input.
+    if ($entity_type == 'file') {
+      // We have to make sure to whitelist mime types, to avoid the video files
+      // getting converted into text files, when deployed from one env to other.
+      if (!in_array($entity->filemime, preg_split('/\r?\n/', $valid_media_mimes))) {
+        $entity->filename = _services_file_check_name_extension($entity->filename);
+        $entity->uri = _services_file_check_destination_uri($entity->uri);
+        if (!empty($entity->filepath)) {
+          $entity->filepath = _services_file_check_destination($entity->filepath);
+        }
+      }
+    }
     entity_uuid_save($entity_type, $entity);
     return $entity;
   }

+ 3 - 4
sites/all/modules/contrib/admin/uuid/uuid_services_example/uuid_services_example.info

@@ -11,9 +11,8 @@ features[ctools][] = services:services:3
 features[features_api][] = api:2
 features[services_endpoint][] = uuid_services_example
 
-; Information added by Drupal.org packaging script on 2017-04-27
-version = "7.x-1.0"
+; Information added by Drupal.org packaging script on 2018-07-19
+version = "7.x-1.2"
 core = "7.x"
 project = "uuid"
-datestamp = "1493291958"
-
+datestamp = "1531990689"