Skip to content

Commit

Permalink
Merge pull request #479 from nextcloud/enh/478/single-password
Browse files Browse the repository at this point in the history
setup single password per circle
  • Loading branch information
ArtificialOwl authored Aug 17, 2020
2 parents 9bba102 + e6c6cae commit 94e0e51
Show file tree
Hide file tree
Showing 19 changed files with 308 additions and 89 deletions.
3 changes: 3 additions & 0 deletions css/navigation.css
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,9 @@ div.circle .owner, div.circle .type, div.circle .resume {
#settings-name {
width: 300px;
}
#single-password {
width: 270px;
}

#settings-desc {
width: 300px;
Expand Down
40 changes: 21 additions & 19 deletions js/circles.app.actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
var actions = {


changeMemberLevel: function (member, type, instance, level) {
changeMemberLevel: function(member, type, instance, level) {
if (Number(level) === define.levelOwner) {
actions.changeMemberOwner(member, type, instance);
return;
Expand All @@ -53,7 +53,7 @@ var actions = {
},


changeGroupLevel: function (group, level) {
changeGroupLevel: function(group, level) {
if (level === 'remove_group') {
api.unlinkGroup(curr.circle, group, resultGroups.unlinkGroupResult);
} else {
Expand All @@ -63,11 +63,11 @@ var actions = {
},


changeMemberOwner: function (member, type, instance) {
changeMemberOwner: function(member, type, instance) {
OC.dialogs.confirm(
t('circles', 'Are you sure you want to transfer your ownership?', [member]),
t('circles', 'This action is irreversible'),
function (e) {
function(e) {
if (e === true) {
api.levelMember(curr.circle, member, type, instance, define.levelOwner,
resultMembers.levelMemberResult);
Expand All @@ -80,7 +80,7 @@ var actions = {
},


changeMemberStatus: function (member, type, instance, value) {
changeMemberStatus: function(member, type, instance, value) {
if (value === 'remove_member' || value === 'dismiss_request') {
api.removeMember(curr.circle, member, type, instance, resultMembers.removeMemberResult);
}
Expand All @@ -90,17 +90,17 @@ var actions = {
},


changeLinkStatus: function (link, value) {
changeLinkStatus: function(link, value) {
api.linkStatus(link, value, resultLinks.linkStatusResult);
},


validateEmail: function (email) {
validateEmail: function(email) {
var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
},

selectCircle: function (circle_id) {
selectCircle: function(circle_id) {
curr.searchUser = '';
elements.addMember.val('');
elements.linkGroup.val('');
Expand All @@ -111,7 +111,7 @@ var actions = {
},


unselectCircle: function (circle_id) {
unselectCircle: function(circle_id) {
elements.mainUIMembersTable.emptyTable();
elements.navigation.children(".circle[circle-id='" + circle_id + "']").remove();
elements.emptyContent.show(400);
Expand All @@ -122,25 +122,28 @@ var actions = {
},


saveSettings: function () {
saveSettings: function() {
let data = {
circle_name: elements.settingsName.val(),
circle_desc: elements.settingsDesc.val(),
allow_links: (elements.settingsLink.is(":checked")),
password_enforcement: (elements.settingsPassword.is(":checked")),
members_limit: (elements.settingsLimit.val()),
password_single_enabled: (elements.settingsSinglePasswordEnabled.is(":checked")),
password_single: elements.settingsSinglePassword.val(),
members_limit: elements.settingsLimit.val(),
allow_links_auto: (elements.settingsLinkAuto.is(":checked")),
allow_links_files: (elements.settingsLinkFiles.is(":checked"))
};

console.log(JSON.stringify(data));
api.settingsCircle(curr.circle, data, settings.saveSettingsResult);
},

/**
*
* @param search
*/
searchMembersRequest: function (search) {
searchMembersRequest: function(search) {

if (curr.searchUser === search) {
return;
Expand All @@ -155,7 +158,7 @@ var actions = {
*
* @param search
*/
searchGroupsRequest: function (search) {
searchGroupsRequest: function(search) {

if (curr.searchGroup === search) {
return;
Expand All @@ -173,7 +176,7 @@ var actions = {
},


getStringTypeFromType: function (type) {
getStringTypeFromType: function(type) {

switch (Number(type)) {
case define.typePersonal:
Expand All @@ -193,7 +196,7 @@ var actions = {
/**
*
*/
onEventNewCircle: function () {
onEventNewCircle: function() {
curr.circle = 0;
curr.circleLevel = 0;

Expand All @@ -206,7 +209,7 @@ var actions = {
/**
*
*/
onEventNewCircleName: function () {
onEventNewCircleName: function() {
this.onEventNewCircle();
nav.displayOptionsNewCircle((elements.newName.val() !== ''));
},
Expand All @@ -215,14 +218,13 @@ var actions = {
/**
*
*/
onEventNewCircleType: function () {
onEventNewCircleType: function() {
this.onEventNewCircle();
elements.newTypeDefinition.children('div').fadeOut(300);
var selectedType = elements.newType.children('option:selected').val();
if (selectedType === '') {
elements.newType.addClass('select_none');
}
else {
} else {
elements.newType.removeClass('select_none');
$('#circles_new_type_' + selectedType).fadeIn(
300);
Expand Down
6 changes: 6 additions & 0 deletions js/circles.app.elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ var elements = {
settingsName: null,
settingsDesc: null,
settingsPassword: null,
settingsSinglePasswordEnabled: null,
settingsSinglePassword: null,
settingsEntrySinglePassword: null,
settingsLimit: null,
settingsEntryLimit: null,
settingsLink: null,
Expand Down Expand Up @@ -135,6 +138,9 @@ var elements = {
elements.settingsDesc = $('#settings-desc');
elements.settingsEntryLimit = $('#settings-entry-limit');
elements.settingsPassword = $('#settings-password');
elements.settingsSinglePassword = $('#single-password');
elements.settingsSinglePasswordEnabled = $('#single-password-enabled');
elements.settingsEntrySinglePassword = $('#settings-password-single');
elements.settingsLimit = $('#settings-limit');
// elements.settingsLimit.prop('disabled', !OC.isUserAdmin());

Expand Down
47 changes: 40 additions & 7 deletions js/circles.app.settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

var settings = {

displaySettings: function (display) {
displaySettings: function(display) {
if (display) {
settings.initUISettings();
elements.circleDesc.hide(define.animationSpeed);
Expand All @@ -46,10 +46,26 @@ var settings = {
}
},

initUISettings: function () {
initUISettings: function() {
elements.settingsName.val(curr.circleName);
elements.settingsDesc.val(curr.circleDesc);
elements.settingsLimit.val(curr.circleLimit);


// single-password-enabled
elements.settingsPassword.prop('checked',
(curr.circleSettings['password_enforcement'] === 'true'));
elements.settingsPassword.on('change', function() {
settings.interactUISettings();
});

elements.settingsSinglePassword.val('');
elements.settingsSinglePasswordEnabled.prop('checked',
(curr.circleSettings['password_single_enabled'] === 'true'));
elements.settingsSinglePasswordEnabled.on('change', function() {
settings.interactUISettings();
});

if (OC.isUserAdmin()) {
elements.settingsEntryLimit.show();
} else {
Expand All @@ -62,15 +78,30 @@ var settings = {
elements.settingsLinkFiles.prop('checked',
(curr.circleSettings['allow_links_files'] === 'true'));

elements.settingsLink.on('change', function () {
elements.settingsLink.on('change', function() {
settings.interactUISettings();
});

settings.interactUISettings();
},


interactUISettings: function () {
interactUISettings: function() {
if (elements.settingsPassword.is(":checked")) {
settings.enableSetting(elements.settingsEntrySinglePassword, elements.settingsSinglePassword,
true);
settings.enableSetting(null, elements.settingsSinglePasswordEnabled, true);
if (elements.settingsSinglePasswordEnabled.is(":checked")) {
settings.enableSetting(null, elements.settingsSinglePassword, true);
} else {
settings.enableSetting(null, elements.settingsSinglePassword,
false);
}
} else {
settings.enableSetting(null, elements.settingsSinglePasswordEnabled, false);
settings.enableSetting(elements.settingsEntrySinglePassword, elements.settingsSinglePassword,
false);
}

if (curr.allowed_federated_circles !== '1' ||
curr.circleDetails.type === define.typePersonal) {
Expand All @@ -88,12 +119,14 @@ var settings = {
(elements.settingsLink.is(":checked")));
},

enableSetting: function (entry, input, enable) {
entry.stop().fadeTo(curr.animationSpeed, (enable) ? 1 : 0.3);
enableSetting: function(entry, input, enable) {
if (entry !== null) {
entry.stop().fadeTo(curr.animationSpeed, (enable) ? 1 : 0.3);
}
input.prop('disabled', !enable);
},

saveSettingsResult: function (result) {
saveSettingsResult: function(result) {
if (result.status < 1) {
OCA.notification.onFail(
t('circles', 'Issue while saving settings') + ': ' +
Expand Down
12 changes: 11 additions & 1 deletion lib/Circles/FileSharingBroadcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,14 @@ public function createShareToMember(SharingFrame $frame, Member $member) {
}

$password = '';
$sendPasswordByMail = true;
if ($this->configService->enforcePasswordProtection($circle)) {
$password = $this->miscService->token(15);
if ($circle->getSetting('password_single_enabled') === 'true') {
$password = $circle->getPasswordSingle();
$sendPasswordByMail = false;
} else {
$password = $this->miscService->token(15);
}
}

$sharesToken =
Expand All @@ -227,6 +233,10 @@ public function createShareToMember(SharingFrame $frame, Member $member) {
$mails = $this->getMailsFromContact($member->getUserId());
}

if (!$sendPasswordByMail) {
$password = '';
}

foreach ($mails as $mail) {
$this->sharedByMail($circle, $share, $mail, $sharesToken, $password);
}
Expand Down
9 changes: 6 additions & 3 deletions lib/Db/CirclesRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCA\Circles\Exceptions\CircleAlreadyExistsException;
use OCA\Circles\Exceptions\CircleDoesNotExistException;
use OCA\Circles\Exceptions\ConfigNoCircleAvailableException;
use OCA\Circles\Exceptions\GSStatusException;
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;

Expand All @@ -48,11 +49,12 @@ class CirclesRequest extends CirclesRequestBuilder {
* In case of interaction with users, Please use getCircle() instead.
*
* @param string $circleUniqueId
* @param bool $allSettings
*
* @return Circle
* @throws CircleDoesNotExistException
*/
public function forceGetCircle($circleUniqueId) {
public function forceGetCircle($circleUniqueId, bool $allSettings = false) {
$qb = $this->getCirclesSelectSql();

$this->leftJoinOwner($qb, '');
Expand All @@ -66,7 +68,7 @@ public function forceGetCircle($circleUniqueId) {
throw new CircleDoesNotExistException($this->l10n->t('Circle not found'));
}

return $this->parseCirclesSelectSql($data);
return $this->parseCirclesSelectSql($data, $allSettings);
}


Expand All @@ -89,7 +91,7 @@ public function forceGetCircles(string $ownerId = '') {
$circles = [];
$cursor = $qb->execute();
while ($data = $cursor->fetch()) {
$circles[] = $this->parseCirclesSelectSql($data);
$circles[] = $this->parseCirclesSelectSql($data, true);
}
$cursor->closeCursor();

Expand Down Expand Up @@ -138,6 +140,7 @@ public function forceGetCircleByName($name) {
*
* @return Circle[]
* @throws ConfigNoCircleAvailableException
* @throws GSStatusException
*/
public function getCircles(
string $userId, int $circleType = 0, string $name = '', int $level = 0, bool $forceAll = false,
Expand Down
5 changes: 3 additions & 2 deletions lib/Db/CirclesRequestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,11 @@ protected function getCirclesSelectSql() {

/**
* @param array $data
* @param bool $allSettings
*
* @return Circle
*/
protected function parseCirclesSelectSql($data) {
protected function parseCirclesSelectSql($data, bool $allSettings = false) {

$circle = new Circle();
$circle->setId($data['id']);
Expand All @@ -395,7 +396,7 @@ protected function parseCirclesSelectSql($data) {
if ($data['contact_groupname'] !== null) {
$circle->setContactGroupName($data['contact_groupname']);
}
$circle->setSettings($data['settings']);
$circle->setSettings($data['settings'], $allSettings);
$circle->setType($data['type']);
$circle->setCreation($data['creation']);

Expand Down
10 changes: 10 additions & 0 deletions lib/Db/SharingFrameRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,14 @@ public function updateSharingFrame(SharingFrame $frame) {
}




public function updatePasswordOnShares(string $circleId, string $password) {
$qb = $this->getSharesUpdateSql($frame->getUniqueId());

$this->limitToShareWith($qb, $circleId);
$this->limitToShareType($qb, self::SHARE_TYPE);
}


}
Loading

0 comments on commit 94e0e51

Please sign in to comment.