Skip to content
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
26 changes: 21 additions & 5 deletions lib/private/Settings/Admin/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,35 @@

namespace OC\Settings\Admin;

use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Encryption\IManager;
use OCP\IInitialStateService;
use OCP\IUserManager;
use OCP\Settings\ISettings;

class Security implements ISettings {

/** @var IManager */
private $manager;

/** @var IUserManager */
private $userManager;

/**
* @param IManager $manager
* @param IUserManager $userManager
*/
public function __construct(IManager $manager, IUserManager $userManager) {
/** @var MandatoryTwoFactor */
private $mandatoryTwoFactor;

/** @var IInitialStateService */
private $initialState;

public function __construct(IManager $manager,
IUserManager $userManager,
MandatoryTwoFactor $mandatoryTwoFactor,
IInitialStateService $initialState) {
$this->manager = $manager;
$this->userManager = $userManager;
$this->mandatoryTwoFactor = $mandatoryTwoFactor;
$this->initialState = $initialState;
}

/**
Expand All @@ -61,6 +71,12 @@ public function getForm() {
}
}

$this->initialState->provideInitialState(
'settings',
'mandatory2FAState',
$this->mandatoryTwoFactor->getState()
);

$parameters = [
// Encryption API
'encryptionEnabled' => $this->manager->isEnabled(),
Expand Down
6 changes: 3 additions & 3 deletions settings/js/vue-0.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions settings/js/vue-3.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings/js/vue-4.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings/js/vue-5.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings/js/vue-6.js

Large diffs are not rendered by default.

48 changes: 37 additions & 11 deletions settings/js/vue-settings-admin-security.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings/js/vue-settings-admin-security.js.map

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions settings/js/vue-settings-apps-users-management.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings/js/vue-settings-apps-users-management.js.map

Large diffs are not rendered by default.

33 changes: 12 additions & 21 deletions settings/src/components/AdminTwoFactor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,33 +77,24 @@
},
data () {
return {
state: {
enforced: false,
enforcedGroups: [],
excludedGroups: [],
},
loading: false,
groups: [],
loadingGroups: false,
}
},
computed: {
state: function() {
return {
enforced: this.$store.state.enforced,
enforcedGroups: this.$store.state.enforcedGroups,
excludedGroups: this.$store.state.excludedGroups,
}
}
},
mounted () {
this.loading = true
Axios.get(OC.generateUrl('/settings/api/admin/twofactorauth'))
.then(resp => resp.data)
.then(state => {
this.state = state

// Groups are loaded dynamically, but the assigned ones *should*
// be valid groups, so let's add them as initial state
this.groups = _.sortedUniq(this.state.enforcedGroups.concat(this.state.excludedGroups))

this.loading = false
})
.catch(err => {
console.error('Could not load two-factor state', err)
throw err
})
// Groups are loaded dynamically, but the assigned ones *should*
// be valid groups, so let's add them as initial state
this.groups = _.sortedUniq(this.state.enforcedGroups.concat(this.state.excludedGroups))
},
methods: {
searchGroup: _.debounce(function (query) {
Expand Down
9 changes: 8 additions & 1 deletion settings/src/main-admin-security.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import Vue from 'vue'

import AdminTwoFactor from './components/AdminTwoFactor.vue'
import store from './store/admin-security'

__webpack_nonce__ = btoa(OC.requestToken)

Vue.prototype.t = t;

store.replaceState(
OCP.InitialState.loadState('settings', 'mandatory2FAState')
)

const View = Vue.extend(AdminTwoFactor)
new View().$mount('#two-factor-auth-settings')
new View({
store
}).$mount('#two-factor-auth-settings')
63 changes: 63 additions & 0 deletions settings/src/store/admin-security.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* @copyright 2019 Roeland Jago Douma <[email protected]>
*
* @author 2019 Roeland Jago Douma <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export const mutations = {
setEnforced(state, enabled) {
Vue.set(state, 'enforced', enabled)
},
setEnforcedGroups(state, total) {
Vue.set(state, 'enforcedGroups', total)
},
setExcludedGroups(state, used) {
Vue.set(state, 'excludedGroups', used)
}
}

export const actions = {
save ({commit}, ) {
commit('setEnabled', false);

return generateCodes()
.then(({codes, state}) => {
commit('setEnabled', state.enabled);
commit('setTotal', state.total);
commit('setUsed', state.used);
commit('setCodes', codes);
return true;
});
}
}

export default new Vuex.Store({
strict: process.env.NODE_ENV !== 'production',
state: {
enforced: false,
enforcedGroups: [],
excludedGroups: [],
},
mutations,
actions
})
1 change: 1 addition & 0 deletions settings/templates/settings/admin/security.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

<div id="two-factor-auth" class="section">
<h2><?php p($l->t('Two-Factor Authentication'));?></h2>
<input type="hidden" id="two-factor-auth-settings-initial-state" value="<?php p(base64_encode(json_encode($_['mandatory2FAState']))); ?>">
<div id="two-factor-auth-settings"></div>
</div>

Expand Down
13 changes: 12 additions & 1 deletion tests/lib/Settings/Admin/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@

namespace Test\Settings\Admin;

use OC\Authentication\TwoFactorAuth\MandatoryTwoFactor;
use OC\Encryption\Manager;
use OC\Settings\Admin\Security;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IInitialStateService;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class SecurityTest extends TestCase {
Expand All @@ -36,15 +39,23 @@ class SecurityTest extends TestCase {
private $manager;
/** @var IUserManager */
private $userManager;
/** @var MandatoryTwoFactor|MockObject */
private $mandatoryTwoFactor;
/** @var IInitialStateService|MockObject */
private $initialState;

public function setUp() {
parent::setUp();
$this->manager = $this->getMockBuilder('\OC\Encryption\Manager')->disableOriginalConstructor()->getMock();
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
$this->mandatoryTwoFactor = $this->createMock(MandatoryTwoFactor::class);
$this->initialState = $this->createMock(IInitialStateService::class);

$this->admin = new Security(
$this->manager,
$this->userManager
$this->userManager,
$this->mandatoryTwoFactor,
$this->initialState
);
}

Expand Down