Add a writer to the permissions on the file.

@param \repository_googledocs\rest $client Authenticated client.
@param string $fileid The file we are updating.
@param string $email The email of the writer account to add.
@return boolean
431967
protected function add_writer_to_file(\repository_googledocs\rest $client, $fileid, $email) {
        $updateeditor = [
            'emailAddress' => $email,
            'role' => 'writer',
            'type' => 'user'
        ];
        $params = ['fileid' => $fileid, 'sendNotificationEmail' => 'false'];
        $response = $client->call('create_permission', $params, json_encode($updateeditor));
        if (empty($response->id)) {
            $details = 'Cannot add user ' . $email . ' as a writer for document: ' . $fileid;
            throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details);
        }
        return true;
    }
687006
public function dumpFile($filename, $content)
    {
        $dir = dirname($filename);

        if (!is_dir($dir)) {
            $this->mkdir($dir);
        }

        if (!is_writable($dir)) {
            throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
        }

        // Will create a temp file with 0600 access rights
        // when the filesystem supports chmod.
        $tmpFile = $this->tempnam($dir, basename($filename));

        if (false === @file_put_contents($tmpFile, $content)) {
            throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
        }

        @chmod($tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask());

        $this->rename($tmpFile, $filename, true);
    }
399212
@Override
	public void setClientID(String clientID) throws JMSException
    {
    	externalAccessLock.readLock().lock();
    	try
		{
    		checkNotClosed();
	        if (StringTools.isEmpty(clientID))
	            throw new InvalidClientIDException("Empty client ID");
	        if (this.clientID != null)
	            throw new IllegalStateException("Client ID is already set"); // [JMS SPEC]
	        this.clientID = clientID;
		}
    	finally
    	{
    		externalAccessLock.readLock().unlock();
    	}
    }
1038517
public static function write($file = false, $content = false) {

        if ($file && $content) {

            if (file_put_contents($file, $content)) {

                return true;
            }
        }

        return false;
    }
413521
public function createEmail(int $customerId, Email $email): ?int
    {
        return $this->restClient->createResource(
            $email,
            sprintf(self::CREATE_CUSTOMER_EMAIL, $customerId)
        );
    }
198633
def _add_user_to_file(file_id, service, user_email,
                      perm_type='user', role='writer'):
    
    new_permission = {
        'value': user_email,
        'type': perm_type,
        'role': role
    }
    try:
        service.permissions()\
            .insert(fileId=file_id, body=new_permission)\
            .execute()
    except errors.HttpError as error:
        show_error('An error adding users to spreadsheet: {0}'.format(error))
172691
public function addPostFile($key, $file, $content = null)
    {
        $this->setMethod('POST');
        $this->setBody(null);
        if ($content === null && is_file($file)) {
            $content = @file_get_contents($file);
        }
        $this->_postFiles[$key] = [basename($file), $content];
    }
702243
protected function get_file_summary(\repository_googledocs\rest $client, $fileid) {
        $fields = "id,name,owners,parents";
        $params = [
            'fileid' => $fileid,
            'fields' => $fields
        ];
        return $client->call('get', $params);
    }
947204
public function insert($sessionId, $clientId)
	{
		$this->session_id = $sessionId;
		$this->client_id = $clientId;

		$this->time = time();
		$ret = $this->_db->insertObject($this->_tbl, $this, 'session_id');

		if (!$ret)
		{
			$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', strtolower(get_class($this)), $this->_db->stderr()));

			return false;
		}
		else
		{
			return true;
		}
	}
1037954
public function setInternalId($id)
    {
        if ($this->_id !== null && $this->_id !== $id) {
            throw new ClientException('Should not update the id of an existing document');
        }


        if (!preg_match('/^[a-zA-Z0-9_-]{1,64}\/[a-zA-Z0-9_:.@\-()+,=;$!*\'%]{1,254}$/', $id)) {
            throw new ClientException('Invalid format for document id');
        }

        $this->_id = (string) $id;
    }
208952
protected function add_temp_writer_to_file(\repository_onedrive\rest $client, $fileid, $email) {
        // Expires in 7 days.
        $expires = new DateTime();
        $expires->add(new DateInterval("P7D"));

        $updateeditor = [
            'recipients' => [[ 'email' => $email ]],
            'roles' => ['write'],
            'requireSignIn' => true,
            'sendInvitation' => false
        ];
        $params = ['fileid' => $fileid];
        $response = $client->call('create_permission', $params, json_encode($updateeditor));
        if (empty($response->value[0]->id)) {
            $details = 'Cannot add user ' . $email . ' as a writer for document: ' . $fileid;
            throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details);
        }
        // Store the permission id in the DB. Scheduled task will remove this permission after 7 days.
        if ($access = repository_onedrive\access::get_record(['permissionid' => $response->value[0]->id, 'itemid' => $fileid ])) {
            // Update the timemodified.
            $access->update();
        } else {
            $record = (object) [ 'permissionid' => $response->value[0]->id, 'itemid' => $fileid ];
            $access = new repository_onedrive\access(0, $record);
            $access->create();
        }
        return true;
    }
830967
public static function writeFile($filePath, $fileData, $mode = 0600)
    {
        if (false === file_put_contents($filePath, $fileData)) {
            throw new RuntimeException(sprintf('unable to write file "%s"', $filePath));
        }
        if (false === chmod($filePath, $mode)) {
            throw new RuntimeException(sprintf('unable to set permissions on file "%s"', $filePath));
        }
    }
541285
protected function Log ($recipient, $headers, $email, $method)
    {

        // Set filename

        $filename	= date ('Y-m-d_H-i-s') . '_' . $method . '_' . $recipient . '.txt';

        // Log

        @file_put_contents (EMAIL_LOG_PATH . $filename, $headers . $email);

    }
689602
protected function generateClient(FileGenerator $file, ClientGenerator $generator, Client $client, $path)
    {
        $code = $generator->generate($file, $client);
        $this->filesystem->putFileContents($path, $code);
    }
786879
public static function assertFilePermissionMask($permissionMask, $filename, string $message = '')
    {
        self::filePermissionMask($permissionMask, $filename, 'assertFilePermissionMask', true, $message);
    }
1152945
public function addPermission($roleId, $resourceId)
    {
        $this->aclDataService->createRule(
            $this->getAclRule($roleId, $resourceId)
        );
    }
113368
public function updateTableColumn($writerId, $tableId, $column, array $configuration)
    {
        $allowedConfigurationOptions = ['title', 'type', 'reference', 'schemaReference', 'format', 'dateDimension'];
        foreach ($configuration as $k => $v) {
            if (!in_array($k, $allowedConfigurationOptions)) {
                throw new ClientException("Option '$k' is not allowed, choose from: " . implode(', ', $allowedConfigurationOptions));
            }
        }

        $params = [
            'writerId' => $writerId,
            'tableId' => $tableId,
            'column' => $column
        ];
        $params = array_merge($params, $configuration);
        return $this->getCommand('UpdateTableColumn', $params)->execute();
    }