Skip to content

Commit

Permalink
Merge branch 'main' into issue_90
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed Dec 13, 2023
2 parents 51fd12f + 5574750 commit 7f65c39
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 191 deletions.
3 changes: 0 additions & 3 deletions .gitattributes

This file was deleted.

3 changes: 2 additions & 1 deletion js/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ var mfazoneFileListPlugin = {
// if (fileList.id === 'trashbin' || fileList.id === 'files.public') {
// return;
// }

console.log("Attaching MFA Zone plugin to " + fileList.id);
console.log(fileList);
fileList.registerTabView(new OCA.mfazones.MfaZoneTabView());

fileList.fileActions.registerAction({
Expand Down
258 changes: 91 additions & 167 deletions js/tabview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,88 @@
// SPDX-FileCopyrightText: Pondersource <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later
(function () {
function renderHTML(enabled) {
return `
<div style="text-align:center; word-wrap:break-word;">
<style>
.switch {
position: relative;
display: inline;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 30px;
height: 15px;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
margin-top: auto;
}
.slider:before {
position: absolute;
content: "";
height: 9px;
width: 9px;
left: 3px;
bottom: 3px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(15px);
-ms-transform: translateX(15px);
transform: translateX(15px);
}
/* Rounded sliders */
.slider.round {
border-radius: 15px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
<span id="mfa-current-file-path" hidden></span>
<span style="--icon-size:36px;">
<label class="switch">
<input id="checkbox-radio-switch-mfa" type="checkbox" ${enabled ? '' : 'disabled'}>
<span class="slider round"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enforce MFA requirement
</label>
</span>
<br/>
<br/>
<br/>
<div id="need-mfa" style="--icon-size:36px;">
<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">Enable 2FA</button>
</div>
</div>
`;
}
const MfaZoneTabView = OCA.Files.DetailTabView.extend({
id: 'mfazoneTabView',
className: 'tab mfazoneTabView',
Expand All @@ -16,166 +98,12 @@
console.error("File info not found!");
return;
}
const $html = `
<div style="text-align:center; word-wrap:break-word;">
<style>
.switch {
position: relative;
display: inline;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 30px;
height: 15px;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
margin-top: auto;
}
.slider:before {
position: absolute;
content: "";
height: 9px;
width: 9px;
left: 3px;
bottom: 3px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(15px);
-ms-transform: translateX(15px);
transform: translateX(15px);
}
/* Rounded sliders */
.slider.round {
border-radius: 15px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
<span id="mfa-current-file-path" hidden></span>
<span style="--icon-size:36px;">
<label class="switch">
<input id="checkbox-radio-switch-mfa" type="checkbox">
<span class="slider round"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enforce MFA requirement
</label>
</span>
<br/>
<br/>
<br/>
<div id="need-mfa" style="--icon-size:36px;">
<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">Enable 2FA</button>
</div>
</div>
`;
const $htmlDisabled = `
<div style="text-align:center; word-wrap:break-word;">
<style>
.switch {
position: relative;
display: inline;
}
.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 30px;
height: 15px;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
margin-top: auto;
}
.slider:before {
position: absolute;
content: "";
height: 9px;
width: 9px;
left: 3px;
bottom: 3px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider {
background-color: #2196F3;
}
input:focus + .slider {
box-shadow: 0 0 1px #2196F3;
}
input:checked + .slider:before {
-webkit-transform: translateX(15px);
-ms-transform: translateX(15px);
transform: translateX(15px);
}
/* Rounded sliders */
.slider.round {
border-radius: 15px;
}
.slider.round:before {
border-radius: 50%;
}
</style>
<span id="mfa-current-file-path" hidden></span>
<span style="--icon-size:36px;">
<label class="switch">
<input id="checkbox-radio-switch-mfa" type="checkbox" disabled>
<span class="slider round"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enforce MFA requirement
</label>
</span>
<br/>
<br/>
<br/>
<div id="need-mfa" style="--icon-size:36px;">
<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">Enable 2FA</button>
</div>
</div>
`;
console.log("Rendering MFA Zone tab for " + fileInfo.getFullPath());
// if (!fileInfo.isDirectory()) {
// this.$el.html(`<div>MFA Zones are currently disabled for files.</div>`);
// console.log("Not a directory, MFA zone detail tab disabled.");
// return;
// }
const accessUrl = OC.generateUrl('/apps/mfazones/access'),
data = {
source: fileInfo.getFullPath()
Expand All @@ -190,20 +118,16 @@
async: true,
success: function (response) {
console.log(response);
if (response.access === false) {
_self.addHtml(_self, $htmlDisabled, data, false);
} else {
_self.addHtml(_self, $html, data, true);
}
_self.addHtml(_self, data, response.access);
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(thrownError);
},
});
},
addHtml: function (context, html, data, enabled) {
context.$el.html(html);
addHtml: function (context, data, enabled) {
context.$el.html(renderHTML(enabled));
const statusUrl = OC.generateUrl('/apps/mfazones/get');
$.ajax({
type: 'GET',
Expand Down
34 changes: 17 additions & 17 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,23 @@ public function __construct() {
$server = $container->getServer();
$eventDispatcher = $this->getContainer()->get(IEventDispatcher::class);

$eventDispatcher->addListener(
BeforeUserLoggedInEvent::class,
function ($event) {
// Check if the user has MFA verified
$twoFactorManager = \OC::$server->get(TwoFactorManager::class);
$userManager = \OC::$server->get(IUserManager::class);
$user = $userManager->get($event->getUsername());
$hasMfaEnabled = $twoFactorManager->isTwoFactorAuthenticated($user);
// Redirect users to enable MFA if not already enabled and have 2FA provider
if (!$hasMfaEnabled) {
$providerSet = $twoFactorManager->getProviderSet($user);
if(!empty($loginProviders) && !$providerSet->isProviderMissing()){
$twoFactorManager->prepareTwoFactorLogin($user, false);
}
}
}
);
// $eventDispatcher->addListener(
// BeforeUserLoggedInEvent::class,
// function ($event) {
// // Check if the user has MFA verified
// $twoFactorManager = \OC::$server->get(TwoFactorManager::class);
// $userManager = \OC::$server->get(IUserManager::class);
// $user = $userManager->get($event->getUsername());
// $hasMfaEnabled = $twoFactorManager->isTwoFactorAuthenticated($user);
// // Redirect users to enable MFA if not already enabled and have 2FA provider
// if (!$hasMfaEnabled) {
// $providerSet = $twoFactorManager->getProviderSet($user);
// if(!empty($loginProviders) && !$providerSet->isProviderMissing()){
// $twoFactorManager->prepareTwoFactorLogin($user, false);
// }
// }
// }
// );

$this->systemTagManager = $this->getContainer()->get(ISystemTagManager::class);
$this->manager = $this->getContainer()->get(Manager::class);
Expand Down
3 changes: 3 additions & 0 deletions lib/Controller/MfazonesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ public function set($source, $protect)
}
$userRoot = $this->rootFolder->getUserFolder($this->userId);
$node = $userRoot->get($source);
if ($node->getType() !== 'dir') {
return new DataResponse(['not a directory'], Http::STATUS_FORBIDDEN);
}
$tags = $this->systemTagManager->getAllTags(
null,
Application::TAG_NAME
Expand Down
6 changes: 3 additions & 3 deletions release/mfazones/lib/Controller/MfazonesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function set($source, $protect)

$type = $this->castObjectType($node->getType());

if ($protect == "true") {
if ($protect === "true") {
$this->tagMapper->assignTags($node->getId(), $type, $tagId);
} else {
$this->tagMapper->unassignTags($node->getId(), $type, $tagId);
Expand Down Expand Up @@ -169,10 +169,10 @@ public function access($source)

private function castObjectType($type)
{
if ($type == 'file') {
if ($type === 'file') {
return "files";
}
if ($type == "dir") {
if ($type === "dir") {
return "files";
}
return $type;
Expand Down

0 comments on commit 7f65c39

Please sign in to comment.