Skip to content

Commit

Permalink
fixing
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Dec 21, 2021
1 parent 5527241 commit 9398559
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 33 deletions.
3 changes: 2 additions & 1 deletion lib/Listeners/Files/PreppingMemberSendMail.php
Expand Up @@ -113,7 +113,8 @@ public function __construct(
* @throws UnknownRemoteException
*/
public function handle(Event $event): void {
if (!$event instanceof PreppingCircleMemberEvent) {
if (!$event instanceof PreppingCircleMemberEvent
|| !$this->configService->enforcePasswordOnSharedFile()) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Listeners/Files/PreppingShareSendMail.php
Expand Up @@ -113,7 +113,8 @@ public function __construct(
* @throws UnknownRemoteException
*/
public function handle(Event $event): void {
if (!$event instanceof PreppingFileShareEvent) {
if (!$event instanceof PreppingFileShareEvent
|| !$this->configService->enforcePasswordOnSharedFile()) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Model/ShareWrapper.php
Expand Up @@ -623,7 +623,7 @@ public function getShare(
$share->setTarget($this->getFileTarget());
$share->setProviderId($this->getProviderId());
$share->setStatus($this->getStatus());
if ($this->hasShareToken()) {
if ($this->hasShareToken() && $this->getShareToken()->getPassword() !== '') {
$share->setPassword($this->getShareToken()->getPassword());
}

Expand Down
49 changes: 31 additions & 18 deletions lib/Service/ConfigService.php
Expand Up @@ -99,6 +99,7 @@ class ConfigService {
public const KEYHOLE_CFG_REQUEST = 'keyhole_cfg_request';
public const ROUTE_TO_CIRCLE = 'route_to_circle';
public const EVENT_EXAMPLES = 'event_examples';
public const ENFORCE_PASSWORD = 'enforce_password';

public const SELF_SIGNED_CERT = 'self_signed_cert';
public const MEMBERS_LIMIT = 'members_limit';
Expand Down Expand Up @@ -129,7 +130,7 @@ class ConfigService {
public const TEST_NC_BASE = 'test_nc_base';


private $defaults = [
private static $defaults = [
self::FRONTAL_CLOUD_BASE => '',
self::FRONTAL_CLOUD_ID => '',
self::FRONTAL_CLOUD_SCHEME => 'https',
Expand Down Expand Up @@ -173,6 +174,7 @@ class ConfigService {
self::KEYHOLE_CFG_REQUEST => '0',
self::ROUTE_TO_CIRCLE => 'contacts.contacts.directcircle',
self::EVENT_EXAMPLES => '0',
self::ENFORCE_PASSWORD => '2',

self::SELF_SIGNED_CERT => '0',
self::MEMBERS_LIMIT => '-1',
Expand Down Expand Up @@ -237,7 +239,7 @@ public function getAppValue(string $key): string {
return $value;
}

return $this->get($key, $this->defaults);
return $this->get($key, self::$defaults);
}

/**
Expand Down Expand Up @@ -327,26 +329,45 @@ public function contactsBackendType(): int {

/**
* @return bool
*
* @deprecated
* should the password for a mail share be send to the recipient
*/
public function sendPasswordByMail(): bool {
return true;
// return ($this->config->getAppValue('sharebymail', 'sendpasswordmail', 'yes') === 'yes');
return false;
}

public function enforcePasswordOnFileShare(): bool {
return true;

/**
* @return bool
*/
public function enforcePasswordOnSharedFile(): bool {
$localPolicy = $this->getAppValueInt(ConfigService::ENFORCE_PASSWORD);
if ($localPolicy !== $this->getInt(ConfigService::ENFORCE_PASSWORD, self::$defaults)) {
return ($localPolicy === 1);
}

// TODO: reimplement a way to set password protection on a single Circle
// if ($circle->getSetting('password_enforcement') === 'true') {
// return true;
// }

// return ($this->config->getAppValue('sharebymail', 'enforcePasswordProtection', 'no') === 'yes');
$sendPasswordMail = $this->config->getAppValue(
'sharebymail',
'sendpasswordmail',
'yes'
);

$enforcePasswordProtection = $this->config->getAppValue(
'core',
'shareapi_enforce_links_password',
'no'
);

return ($sendPasswordMail === 'yes'
&& $enforcePasswordProtection === 'yes');
}


/**
* @param DeprecatedCircle $circle
*
Expand All @@ -356,15 +377,7 @@ public function enforcePasswordOnFileShare(): bool {
*
*/
public function enforcePasswordProtection(DeprecatedCircle $circle) {
if ($this->isContactsBackend()) {
return false;
}

if ($circle->getSetting('password_enforcement') === 'true') {
return true;
}

return ($this->config->getAppValue('sharebymail', 'enforcePasswordProtection', 'no') === 'yes');
return false;
}


Expand Down
13 changes: 1 addition & 12 deletions lib/Service/SendMailService.php
Expand Up @@ -224,22 +224,11 @@ private function sendMailPassword(
string $email,
string $password
): void {
if (!$this->configService->sendPasswordByMail() || $password === '') {
if (!$this->configService->enforcePasswordOnSharedFile() || $password === '') {
return;
}

$message = $this->mailer->createMessage();
// $filename = $share->getNode()
// ->getName();
// $initiator = $share->getSharedBy();
// $shareWith = $share->getSharedWith();
//
// $initiatorUser = $this->userManager->get($initiator);
// $initiatorDisplayName =
// ($initiatorUser instanceof IUser) ? $initiatorUser->getDisplayName() : $initiator;
// $initiatorEmailAddress =
// ($initiatorUser instanceof IUser) ? $initiatorUser->getEMailAddress() : null;

$plainBodyPart = $this->l10n->t(
"%1\$s shared some content with you.\nYou should have already received a separate email with a link to access it.\n",
[$author]
Expand Down

0 comments on commit 9398559

Please sign in to comment.