/** * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors * SPDX-FileCopyrightText: 2011-2016 ownCloud, Inc. * SPDX-License-Identifier: AGPL-3.0-or-later */ /* eslint-disable */ import escapeHTML from 'escape-html' import { ShareType } from '@nextcloud/sharing' import { getCapabilities } from '@nextcloud/capabilities' (function() { _.extend(OC.Files.Client, { PROPERTY_SHARE_TYPES: '{' + OC.Files.Client.NS_OWNCLOUD + '}share-types', PROPERTY_OWNER_ID: '{' + OC.Files.Client.NS_OWNCLOUD + '}owner-id', PROPERTY_OWNER_DISPLAY_NAME: '{' + OC.Files.Client.NS_OWNCLOUD + '}owner-display-name' }) if (!OCA.Sharing) { OCA.Sharing = {} } /** * @namespace */ OCA.Sharing.Util = { /** * Regular expression for splitting parts of remote share owners: * "user@example.com/" * "user@example.com/path/to/owncloud" * "user@anotherexample.com@example.com/path/to/owncloud */ _REMOTE_OWNER_REGEXP: new RegExp('^(([^@]*)@(([^@^/\\s]*)@)?)((https://)?[^[\\s/]*)([/](.*))?$'), /** * Initialize the sharing plugin. * * Registers the "Share" file action and adds additional * DOM attributes for the sharing file info. * * @param {OCA.Files.FileList} fileList file list to be extended */ attach: function(fileList) { // core sharing is disabled/not loaded if (!getCapabilities().files_sharing?.api_enabled) { return } if (fileList.id === 'trashbin' || fileList.id === 'files.public') { return } var fileActions = fileList.fileActions var oldCreateRow = fileList._createRow fileList._createRow = function(fileData) { var tr = oldCreateRow.apply(this, arguments) var sharePermissions = OCA.Sharing.Util.getSharePermissions(fileData) if (fileData.permissions === 0) { // no permission, disabling sidebar delete fileActions.actions.all.Comment delete fileActions.actions.all.Details delete fileActions.actions.all.Goto } if (_.isFunction(fileData.canDownload) && !fileData.canDownload()) { delete fileActions.actions.all.Download if ((fileData.permissions & OC.PERMISSION_UPDATE) === 0) { // neither move nor copy is allowed, remove the action completely delete fileActions.actions.all.MoveCopy } } tr.attr('data-share-permissions', sharePermissions) tr.attr('data-share-attributes', JSON.stringify(fileData.shareAttributes)) if (fileData.shareOwner) { tr.attr('data-share-owner', fileData.shareOwner) tr.attr('data-share-owner-id', fileData.shareOwnerId) // user should always be able to rename a mount point if (fileData.mountType === 'shared-root') { tr.attr('data-permissions', fileData.permissions | OC.PERMISSION_UPDATE) } } if (fileData.recipientData && !_.isEmpty(fileData.recipientData)) { tr.attr('data-share-recipient-data', JSON.stringify(fileData.recipientData)) } if (fileData.shareTypes) { tr.attr('data-share-types', fileData.shareTypes.join(',')) } return tr } var oldElementToFile = fileList.elementToFile fileList.elementToFile = function($el) { var fileInfo = oldElementToFile.apply(this, arguments) fileInfo.shareAttributes = JSON.parse($el.attr('data-share-attributes') || '[]') fileInfo.sharePermissions = $el.attr('data-share-permissions') || undefined fileInfo.shareOwner = $el.attr('data-share-owner') || undefined fileInfo.shareOwnerId = $el.attr('data-share-owner-id') || undefined if ($el.attr('data-share-types')) { fileInfo.shareTypes = $el.attr('data-share-types').split(',') } if ($el.attr('data-expiration')) { var expirationTimestamp = parseInt($el.attr('data-expiration')) fileInfo.shares = [] fileInfo.shares.push({ expiration: expirationTimestamp }) } return fileInfo } var oldGetWebdavProperties = fileList._getWebdavProperties fileList._getWebdavProperties = function() { var props = oldGetWebdavProperties.apply(this, arguments) props.push(OC.Files.Client.PROPERTY_OWNER_ID) props.push(OC.Files.Client.PROPERTY_OWNER_DISPLAY_NAME) props.push(OC.Files.Client.PROPERTY_SHARE_TYPES) return props } fileList.filesClient.addFileInfoParser(function(response) { var data = {} var props = response.propStat[0].properties var permissionsProp = props[OC.Files.Client.PROPERTY_PERMISSIONS] if (permissionsProp && permissionsProp.indexOf('S') >= 0) { data.shareOwner = props[OC.Files.Client.PROPERTY_OWNER_DISPLAY_NAME] data.shareOwnerId = props[OC.Files.Client.PROPERTY_OWNER_ID] } var shareTypesProp = props[OC.Files.Client.PROPERTY_SHARE_TYPES] if (shareTypesProp) { data.shareTypes = _.chain(shareTypesProp).filter(function(xmlvalue) { return (xmlvalue.namespaceURI === OC.Files.Client.NS_OWNCLOUD && xmlvalue.nodeName.split(':')[1] === 'share-type') }).map(function(xmlvalue) { return parseInt(xmlvalue.textContent || xmlvalue.text, 10) }).value() } return data }) // use delegate to catch the case with multiple file lists fileList.$el.on('fileActionsReady', function(ev) { var $files = ev.$files _.each($files, function(file) { var $tr = $(file) var shareTypesStr = $tr.attr('data-share-types') || '' var shareOwner = $tr.attr('data-share-owner') if (shareTypesStr || shareOwner) { var hasLink = false var hasShares = false _.each(shareTypesStr.split(',') || [], function(shareTypeStr) { let shareType = parseInt(shareTypeStr, 10) if (shareType === ShareType.Link) { hasLink = true } else if (shareType === ShareType.Email) { hasLink = true } else if (shareType === ShareType.User) { hasShares = true } else if (shareType === ShareType.Group) { hasShares = true } else if (shareType === ShareType.Remote) { hasShares = true } else if (shareType === ShareType.RemoteGroup) { hasShares = true } else if (shareType === ShareType.Team) { hasShares = true } else if (shareType === ShareType.Room) { hasShares = true } else if (shareType === ShareType.Deck) { hasShares = true } }) OCA.Sharing.Util._updateFileActionI
/*
* Copyright 2012 John Crygier
* Copyright 2012 gitblit.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gitblit.utils;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.eclipse.jgit.transport.ReceivePack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Class to log messages to the pushing Git client. Intended to be used by the
* Groovy Hooks.
*
* @author John Crygier
*
*/
public class ClientLogger {
static final Logger logger = LoggerFactory.getLogger(ClientLogger.class);
private ReceivePack rp;
public ClientLogger(ReceivePack rp) {
this.rp = rp;
}
/**
* Sends an info/warning message to the git client.
*
* @param message
*/
public void info(String message) {
rp.sendMessage(message);
}
/**
* Sends an error message to the git client.
*
* @param message
*/
public void error(String message) {
rp.sendError(message);
}
/**
* Sends an error message to the git client with an exception.
*
* @param message
* @param t
* an exception
*/
public void error(String message, Throwable t) {
PrintWriter writer = new PrintWriter(new StringWriter());
if (!StringUtils.isEmpty(message)) {
writer.append(message);
writer.append('\n');
}
t.printStackTrace(writer);
rp.sendError(writer.toString());
}
}