Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow admin to enforce password on mail shares #4303

Merged
merged 9 commits into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/sharebymail/css/settings-admin.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#ncShareByMailSettings p {
padding-top: 10px;
}
10 changes: 9 additions & 1 deletion apps/sharebymail/js/settings-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ $(function() {
if ($(this).is(':checked')) {
status = 'yes';
}
OC.AppConfig.setValue('sharebymail', 'sendpasswordmail', status);
OCP.AppConfig.setValue('sharebymail', 'sendpasswordmail', status);
});

$('#enforcePasswordProtection').on('change', function() {
var status = 'no';
if ($(this).is(':checked')) {
status = 'yes';
}
OCP.AppConfig.setValue('sharebymail', 'enforcePasswordProtection', status);
});

});
52 changes: 44 additions & 8 deletions apps/sharebymail/lib/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class Activity implements IProvider {

const SUBJECT_SHARED_EMAIL_SELF = 'shared_with_email_self';
const SUBJECT_SHARED_EMAIL_BY = 'shared_with_email_by';
const SUBJECT_SHARED_EMAIL_PASSWORD_SEND = 'shared_with_email_password_send';
const SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF = 'shared_with_email_password_send_self';

/**
* @param IFactory $languageFactory
Expand Down Expand Up @@ -119,15 +121,26 @@ public function parseShortVersion(IEvent $event) {
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
$event->setParsedSubject($this->l->t('Shared with %1$s by %2$s', [
$parsedParameters['email']['name'],
$parsedParameters['actor']['name'],
]))
$parsedParameters['email']['name'],
$parsedParameters['actor']['name'],
]))
->setRichSubject($this->l->t('Shared with {email} by {actor}'), [
'email' => $parsedParameters['email'],
'actor' => $parsedParameters['actor'],
])
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));

} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
$event->setParsedSubject($this->l->t('Password for mail share send to %1$s', [
$parsedParameters['email']['name']
]))
->setRichSubject($this->l->t('Password for mail share send to {email}'), [
'email' => $parsedParameters['email']
])
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
$event->setParsedSubject($this->l->t('Password for mail share send to you'))
->setRichSubject($this->l->t('Password for mail share send to you'))
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else {
throw new \InvalidArgumentException();
}
Expand All @@ -153,12 +166,26 @@ public function parseLongVersion(IEvent $event) {
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_BY) {
$event->setParsedSubject($this->l->t('%3$s shared %1$s with %2$s by mail', [
$parsedParameters['file']['path'],
$parsedParameters['email']['name'],
$parsedParameters['actor']['name'],
]))
$parsedParameters['file']['path'],
$parsedParameters['email']['name'],
$parsedParameters['actor']['name'],
]))
->setRichSubject($this->l->t('{actor} shared {file} with {email} by mail'), $parsedParameters)
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND) {
$event->setParsedSubject($this->l->t('Password to access %1$s was send to %2s', [
$parsedParameters['file']['path'],
$parsedParameters['email']['name']
]))
->setRichSubject($this->l->t('Password to access {file} was send to {email}'), $parsedParameters)
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));
} else if ($event->getSubject() === self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF) {
$event->setParsedSubject(
$this->l->t('Password to access %1$s was send to you',
[$parsedParameters['file']['path']]))
->setRichSubject($this->l->t('Password to access {file} was send to you'), $parsedParameters)
->setIcon($this->url->getAbsoluteURL($this->url->imagePath('core', 'actions/share.svg')));

} else {
throw new \InvalidArgumentException();
}
Expand All @@ -182,6 +209,15 @@ protected function getParsedParameters(IEvent $event) {
'email' => $this->generateEmailParameter($parameters[1]),
'actor' => $this->generateUserParameter($parameters[2]),
];
case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND:
return [
'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
'email' => $this->generateEmailParameter($parameters[1]),
];
case self::SUBJECT_SHARED_EMAIL_PASSWORD_SEND_SELF:
return [
'file' => $this->generateFileParameter((int) $event->getObjectId(), $parameters[0]),
];
}
throw new \InvalidArgumentException();
}
Expand Down
4 changes: 3 additions & 1 deletion apps/sharebymail/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ class Application extends App {
public function __construct(array $urlParams = array()) {
parent::__construct('sharebymail', $urlParams);

$settings = new Settings();
$settingsManager = \OC::$server->query(Settings\SettingsManager::class);
$settings = new Settings($settingsManager);

/** register capabilities */
$container = $this->getContainer();
$container->registerCapability('OCA\ShareByMail\Capabilities');

/** register hooks */
Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareProvider');
Util::connectHook('\OCP\Config', 'js', $settings, 'announceShareByMailSettings');
}

}
15 changes: 15 additions & 0 deletions apps/sharebymail/lib/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,17 @@
namespace OCA\ShareByMail;


use OCA\ShareByMail\Settings\SettingsManager;

class Settings {

/** @var SettingsManager */
private $settingsManager;

public function __construct(SettingsManager $settingsManager) {
$this->settingsManager = $settingsManager;
}

/**
* announce that the share-by-mail share provider is enabled
*
Expand All @@ -35,4 +44,10 @@ public function announceShareProvider(array $settings) {
$array['shareByMailEnabled'] = true;
$settings['array']['oc_appconfig'] = json_encode($array);
}

public function announceShareByMailSettings(array $settings) {
$array = json_decode($settings['array']['oc_appconfig'], true);
$array['shareByMail']['enforcePasswordProtection'] = $this->settingsManager->enforcePasswordProtection();
$settings['array']['oc_appconfig'] = json_encode($array);
}
}
3 changes: 2 additions & 1 deletion apps/sharebymail/lib/Settings/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function __construct(SettingsManager $settingsManager) {
public function getForm() {

$parameters = [
'sendPasswordMail' => $this->settingsManager->sendPasswordByMail()
'sendPasswordMail' => $this->settingsManager->sendPasswordByMail(),
'enforcePasswordProtection' => $this->settingsManager->enforcePasswordProtection()
];

return new TemplateResponse('sharebymail', 'settings-admin', $parameters, '');
Expand Down
16 changes: 14 additions & 2 deletions apps/sharebymail/lib/Settings/SettingsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class SettingsManager {
/** @var IConfig */
private $config;

private $defaultSetting = 'yes';
private $sendPasswordByMailDefault = 'yes';

private $enforcePasswordProtectionDefault = 'no';

public function __construct(IConfig $config) {
$this->config = $config;
Expand All @@ -42,8 +44,18 @@ public function __construct(IConfig $config) {
* @return bool
*/
public function sendPasswordByMail() {
$sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->defaultSetting);
$sendPasswordByMail = $this->config->getAppValue('sharebymail', 'sendpasswordmail', $this->sendPasswordByMailDefault);
return $sendPasswordByMail === 'yes';
}

/**
* do we require a share by mail to be password protected
*
* @return bool
*/
public function enforcePasswordProtection() {
$enforcePassword = $this->config->getAppValue('sharebymail', 'enforcePasswordProtection', $this->enforcePasswordProtectionDefault);
return $enforcePassword === 'yes';
}

}
Loading