Skip to content

Commit

Permalink
Check: Fix faulty check that is used for showing button or not
Browse files Browse the repository at this point in the history
Signed-off-by: Micke Nordin <[email protected]>
  • Loading branch information
mickenordin committed Aug 15, 2024
1 parent 3c8ddfc commit 64319a4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion mfazones/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ This app will make it possible to designate certain directories as `mfazones` an
The app uses the workflow engine to enforce the restriction.
See the [README](https://github.com/SUNET/nextcloud-mfazones/blob/main/README.md) for more information.]]></description>
<version>0.1.1</version>
<version>0.1.2</version>
<licence>agpl</licence>
<author mail="[email protected]" homepage="https://github.com/SUNET/nextcloud-mfazones">SUNET</author>
<namespace>mfazones</namespace>
Expand Down
23 changes: 9 additions & 14 deletions mfazones/lib/Controller/MfazonesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use OCA\mfazones\AppInfo\Application;
use OCA\mfazones\Utils;
use OCA\mfazones\Check\MfaVerified;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
Expand Down Expand Up @@ -40,6 +41,9 @@ class MfazonesController extends Controller
/** @var ISystemTagObjectMapper */
private $tagMapper;

/** @var MfaVerified */
private $mfaVerified;

/** @var LoggerInterface */
private $logger;

Expand All @@ -51,6 +55,7 @@ public function __construct(
ISession $session,
ISystemTagObjectMapper $tagMapper,
ISystemTagManager $systemTagManager,
MfaVerified $mfaVerified,
LoggerInterface $logger
) {
parent::__construct(Application::APP_ID, $request);
Expand All @@ -60,6 +65,7 @@ public function __construct(
$this->tagMapper = $tagMapper;
$this->session = $session;
$this->systemTagManager = $systemTagManager;
$this->mfaVerified = $mfaVerified;
$this->logger = $logger;
}

Expand All @@ -76,19 +82,7 @@ private function castObjectType($type): string

private function isMfaVerified(): bool
{
$mfaVerified = '0';
if (!empty($this->session->get('globalScale.userData'))) {
$attr = $this->session->get('globalScale.userData')["userData"];
$mfaVerified = $attr["mfaVerified"];
}
if (!empty($this->session->get('user_saml.samlUserData'))) {
$attr = $this->session->get('user_saml.samlUserData');
$mfaVerified = $attr["mfa_verified"][0];
}
if (!empty($this->session->get("two_factor_auth_passed"))) {
$mfaVerified = '1';
}
return $mfaVerified === '1';
return $this->mfaVerified->executeCheck('is', NULL);
}

public function hasAccess($source): bool
Expand Down Expand Up @@ -133,8 +127,9 @@ public function getMfaStatus(): JSONResponse
* This function is used to check if the user has passed the MFA challenge
* and also if the current file has the MFA Zone tag.
*/
public function get($source): JSONResponse
public function get(): JSONResponse
{
$source = $this->request->getParam('source');
try {
$userRoot = $this->rootFolder->getUserFolder($this->userId);
$node = $userRoot->get($source);
Expand Down
2 changes: 0 additions & 2 deletions mfazones/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion mfazones/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "mfazones",
"description": "https://github.com/SUNET/nextcloud-mfazones",
"version": "0.1.1",
"author": "SUNET <[email protected]>",
"contributors": [],
"bugs": {
Expand Down
20 changes: 12 additions & 8 deletions mfazones/src/views/MFATab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
<br />
<br />
<div id="need-mfa" style="--icon-size:36px;" hidden>
<label for="enable-2fa-button">You need to login with two factor authentication to use this feature.</label><br><br>
<button id="enable-2fa-button" @click="go_to_settings()">Enable 2FA</button>
<label for="enable-2fa-button">You need to login with two factor authentication to use this feature. First you must enable 2FA in the <a class="setting-link" :href="settingsLink">settings↗ </a> and then you need to log out and in again. If you have already taken these steps, and still see this message, you must log out and in again.</label><br><br>
</div>
</NcActions>
</template>
Expand All @@ -25,11 +24,6 @@ import { NcActions } from '@nextcloud/vue'
import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'

function go_to_settings() {
const url = generateUrl('/settings/user/security');
window.location.href = url;
}

async function get_mfa_state(fileInfo) {
if (!fileInfo) {
return
Expand All @@ -39,7 +33,7 @@ async function get_mfa_state(fileInfo) {
path = fileInfo.path + '/';
}
let payload = {
params: { source: path + fileInfo.name }
params: { 'source': path + fileInfo.name }
}
const url = generateUrl('/apps/mfazones/get');
return axios.get(url, payload)
Expand All @@ -49,6 +43,11 @@ export default {
components: {
NcActions,
},
data() {
return {
settingsLink: generateUrl('/settings/user/security#two-factor-auth'),
}
},
methods: {
toggleMFAZone() {
const url = generateUrl('/apps/mfazones/set');
Expand Down Expand Up @@ -106,3 +105,8 @@ export default {
},
}
</script>
<style lang="scss" scoped>
.setting-link:hover {
text-decoration: underline;
}
</style>

0 comments on commit 64319a4

Please sign in to comment.