Skip to content

Commit

Permalink
feature(fixes-for-new-licensing-with-product-summary)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonvandebroek committed Dec 9, 2023
1 parent 8bc98d2 commit e26b7c0
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 25 deletions.
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<id>sendent</id>
<name>Sendent</name>
<summary lang="en">Sendent allows you to securely exchange files and emails</summary>
<description lang="en">Sendent allows you to securely exchange files and emails. Sendent is linked to Microsoft Outlook, so you can continue to work from your trusted email program while you mail more easily and securely. Very useful, for example, to share privacy-sensitive documents or content or to send attachments that are normally too large to email. All files are uploaded to your personal Nextcloud environment from which you determine who has access to them.</description>
<version>2.0.6</version>
<description lang="en">Sendent now securely exchanges files and emails, integrating with both Microsoft Outlook and Microsoft Teams. This enhanced capability allows users to seamlessly conduct their work, not only within their preferred email environment but also within the collaborative framework of Microsoft Teams. Whether sharing privacy-sensitive documents, content, or handling attachments that exceed standard email size constraints, Sendent ensures a streamlined and secure communication experience. All files are directed to your Nextcloud instance, empowering you to control and manage access permissions effectively.</description>
<version>2.0.7</version>
<licence>agplv3</licence>
<author mail="[email protected]" homepage="https://www.sendent.nl">Sendent B.V.</author>
<namespace>Sendent</namespace>
Expand Down
5 changes: 5 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ label{
margin: 0;
line-height: 34px;
}

&[data-state="licenseproductavailable"]::before {
content: '';
background-image: var(--icon-checkmark-color-green);
}
.templatesettingkeynametextareakind {
vertical-align: text-top;
}
Expand Down
8 changes: 7 additions & 1 deletion lib/Controller/Dto/LicenseStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ class LicenseStatus implements JsonSerializable {
public $licensekey;
public $level;
public $ncgroup;
public $product;
public $istrial;

public function __construct(string $status, string $statusKind,
string $level, string $licensekey,
string $dateExpiration, string $dateLastCheck, string $email, string $ncgroup = '') {
string $dateExpiration, string $dateLastCheck, string $email, string $product = '', int $istrial = -1, string $ncgroup = '') {
// add types in constructor
$this->status = $status;
$this->statusKind = $statusKind;
Expand All @@ -26,6 +28,8 @@ public function __construct(string $status, string $statusKind,
$this->email = $email;
$this->level = $level;
$this->ncgroup = $ncgroup;
$this->product = $product;
$this->istrial = $istrial;
}

public function jsonSerialize() {
Expand All @@ -38,6 +42,8 @@ public function jsonSerialize() {
'licensekey' => $this->licensekey,
'dateLastCheck' => $this->dateLastCheck,
'ncgroup' => $this->ncgroup,
'product' => $this->product,
'istrial' => $this->istrial,
];
}
}
39 changes: 32 additions & 7 deletions lib/Controller/LicenseApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public function showForNCGroup(string $ncgroup = ''): DataResponse {
$dateLastCheck = $result[0]->getDatelastchecked();
$level = $result[0]->getLevel();
$group = $result[0]->getNcgroup();
$product = $result[0]->getProduct();
$statusKind = "";
$status = "";

Expand All @@ -212,6 +213,12 @@ public function showForNCGroup(string $ncgroup = ''): DataResponse {
$status = $this->l->t("Revalidation of your license is required");
$statusKind = "check";
}
elseif (!$result[0]->isCheckNeeded() && !$result[0]->isLicenseExpired() && !$result[0]->isSupportedProduct()) {
$status = $this->l->t("Current license is not intended to be used with Sendent MS Office products. It is only intended to be used for configuring: " . $product) .
"</br>" .
$this->l->t('%1$sContact support%2$s if you experience issues with configuring your license key.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]);
$statusKind = "expired";
}
elseif ($result[0]->isLicenseRenewedOrSwitched()) {
$status = $this->l->t("Current license has been changed.") .
"</br>" .
Expand Down Expand Up @@ -328,6 +335,8 @@ public function showForNCGroupInternal(string $ncgroup = ''): DataResponse {
$dateLastCheck = $result[0]->getDatelastchecked();
$level = $result[0]->getLevel();
$group = $result[0]->getNcgroup();
$product = $result[0]->getProduct();
$istrial = $result[0]->getIstrial();
$statusKind = "";
$status = "";

Expand All @@ -343,6 +352,12 @@ public function showForNCGroupInternal(string $ncgroup = ''): DataResponse {
$status = $this->l->t("Revalidation of your license is required");
$statusKind = "check";
}
elseif (!$result[0]->isCheckNeeded() && !$result[0]->isLicenseExpired() && !$result[0]->isSupportedProduct()) {
$status = $this->l->t("Current license is not intended to be used with the Sendent app. <br/>Please install/configure Sendent Synchroniser because this license is only intended to be used for configuring: " . $product) .
"</br>" .
$this->l->t('%1$sContact support%2$s if you experience issues with configuring your license key.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]);
$statusKind = "expired";
}
elseif ($result[0]->isLicenseRenewedOrSwitched()) {
$status = $this->l->t("Current license has been changed.") .
"</br>" .
Expand All @@ -367,10 +382,14 @@ public function showForNCGroupInternal(string $ncgroup = ''): DataResponse {
$this->l->t('%1$sContact support%2$s if you experience issues with configuring your license key.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]);
$statusKind = "expired";
}
elseif (!$result[0]->isCheckNeeded() && !$result[0]->isLicenseExpired()) {
elseif (!$result[0]->isCheckNeeded() && !$result[0]->isLicenseExpired() && $result[0]->isSupportedProduct()) {
$status = $this->l->t("Current license is valid");
$statusKind = "valid";
}
elseif (!$result[0]->isCheckNeeded() && !$result[0]->isLicenseExpired()) {
$status = $this->l->t("Current license is valid but there could be an issue for the supported products: " . $product);
$statusKind = "valid";
}
elseif (!$this->licensemanager->isWithinUserCount($result[0]) && $this->licensemanager->isWithinGraceUserCount($result[0])) {
$status = $this->l->t("Current amount of active users exceeds licensed amount. Some users might not be able to use Sendent.");
$statusKind = "userlimit";
Expand All @@ -379,14 +398,16 @@ public function showForNCGroupInternal(string $ncgroup = ''): DataResponse {
$status = $this->l->t("Current amount of active users exceeds licensed amount. Additional users trying to use Sendent will be prevented from doing so.");
$statusKind = "userlimit";
}
return new DataResponse(new LicenseStatus($status, $statusKind, $level,$licensekey, $dateExpiration, $dateLastCheck, $email, $group));
return new DataResponse(new LicenseStatus($status, $statusKind, $level,$licensekey, $dateExpiration, $dateLastCheck, $email, $product, $istrial, $group));
}
elseif (count($result) > 0 && $result[0]->getLevel() == "Error_incomplete") {
$email = $result[0]->getEmail();
$licensekey = $result[0]->getLicensekey();
$group = $result[0]->getNcgroup();
$product = $result[0]->getProduct();
$istrial = $result[0]->getIstrial();
$status = $this->l->t('Missing (or incorrect) email address or license key. %1$sContact support%2$s to get your correct license information.', ["<a href='mailto:[email protected]' style='color:blue'>", "</a>"]);
return new DataResponse(new LicenseStatus($status, "error_incomplete" ,"-", $licensekey, "-", "-", $email, $group));
return new DataResponse(new LicenseStatus($status, "error_incomplete" ,"-", $licensekey, "-", "-", $email, "-", "-", $group));
}
elseif (count($result) > 0 && $result[0]->getLevel() == License::ERROR_VALIDATING) {
$email = $result[0]->getEmail();
Expand All @@ -396,14 +417,16 @@ public function showForNCGroupInternal(string $ncgroup = ''): DataResponse {
$dateLastCheck = $result[0]->getDatelastchecked();
$level = $result[0]->getLevel();
$group = $result[0]->getNcgroup();
return new DataResponse(new LicenseStatus($this->l->t("Cannot verify your license. Please make sure your licensekey and email address are correct before you try to 'Activate license'."), "error_validating",$level, $licensekey, $dateExpiration, $dateLastCheck, $email, $group));
$product = $result[0]->getProduct();
$istrial = $result[0]->getIstrial();
return new DataResponse(new LicenseStatus($this->l->t("Cannot verify your license. Please make sure your licensekey and email address are correct before you try to 'Activate license'."), "error_validating",$level, $licensekey, $dateExpiration, $dateLastCheck, $email, $product, $istrial, $group));
}
else {
return new DataResponse(new LicenseStatus($this->l->t("No license configured"), "nolicense" ,"-", "-", "-", "-", "-"));
return new DataResponse(new LicenseStatus($this->l->t("No license configured"), "nolicense" ,"-", "-", "-", "-", "-", "-", "-"));
}
}
else {
return new DataResponse(new LicenseStatus($this->l->t("No license configured"), "nolicense" ,"-", "-", "-", "-", "-"));
return new DataResponse(new LicenseStatus($this->l->t("No license configured"), "nolicense" ,"-", "-", "-", "-", "-", "-", "-"));
}
} catch (Exception $e) {
$this->logger->error('Cannot verify license');
Expand All @@ -414,7 +437,9 @@ public function showForNCGroupInternal(string $ncgroup = ''): DataResponse {
$dateLastCheck = $result[0]->getDatelastchecked();
$level = $result[0]->getLevel();
$group = $result[0]->getNcgroup();
return new DataResponse(new LicenseStatus($this->l->t("Cannot verify your license. Please make sure your licensekey and email address are correct before you try to 'Activate license'."), "fatal" ,$level, $licensekey, $dateExpiration, $dateLastCheck, $email, $group));
$product = $result[0]->getProduct();
$istrial = $result[0]->getIstrial();
return new DataResponse(new LicenseStatus($this->l->t("Cannot verify your license. Please make sure your licensekey and email address are correct before you try to 'Activate license'."), "fatal" ,$level, $licensekey, $dateExpiration, $dateLastCheck, $email, $product, $istrial, $group));
}
}
/**
Expand Down
22 changes: 21 additions & 1 deletion lib/Db/License.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class License extends Entity implements JsonSerializable {
protected $level;
protected $ncgroup;
protected $subscriptionstatus;
protected $technicallevel;
protected $product;
protected $istrial;

public function __construct() {
// add types in constructor
}
Expand All @@ -38,7 +42,10 @@ public function jsonSerialize() {
'level' => $this->level,
'datelicenseend' => $this->datelicenseend,
'datelastchecked' => $this->datelastchecked,
'ncgroup' => $this->ncgroup
'ncgroup' => $this->ncgroup,
'technicallevel' => $this->technicallevel,
'product' => $this->product,
'istrial' => $this->istrial
];
}

Expand All @@ -52,18 +59,21 @@ public function isCheckNeeded(): bool {

return true;
}

public function isIncomplete(): bool {
if ($this->level == "Error_incomplete" || (!isset($this->licensekey) || !isset($this->licensekey)) || ($this->licensekey == "" || $this->email == "")) {
return true;
}
return false;
}

public function isCleared(): bool {
if ((!isset($this->licensekey) && !isset($this->licensekey)) || ($this->licensekey == "" && $this->email == "")) {
return true;
}
return false;
}

public function isLicenseExpired(): bool {
if ((date_create($this->datelicenseend) < date_create("now")
&& date_create($this->dategraceperiodend) < date_create("now"))
Expand All @@ -72,12 +82,22 @@ public function isLicenseExpired(): bool {
}
return false;
}
public function isTrial() : bool{
return $this->istrial == 1;
}
public function isSupportedProduct() : bool{
return str_contains($this->product, 'Outlook') || str_contains($this->product, 'outlook')
|| str_contains($this->product, 'Teams') || str_contains($this->product, 'teams')
|| str_contains($this->level, 'Teams') || str_contains($this->product, 'teams');
}
public function isLicenseSuspended(): bool {
return $this->subscriptionstatus == "5";
}

public function isLicenseInactive(): bool {
return $this->subscriptionstatus == "4";
}

public function isLicenseRenewedOrSwitched(): bool {
return $this->subscriptionstatus == "6" || $this->subscriptionstatus == "7";
}
Expand Down
8 changes: 7 additions & 1 deletion lib/Http/Dto/SubscriptionOut.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ class SubscriptionOut implements JsonSerializable {
protected $expirationdate;
protected $grantinterval;
protected $email;
protected $istrial;
protected $product;
protected $technicallevel;

public function __construct() {
}
Expand All @@ -24,7 +27,10 @@ public function jsonSerialize() {
'Level' => $this->level,
'ExpirationDate' => $this->expirationdate,
'GrantInterval' => $this->grantinterval,
'Email' => $this->email
'Email' => $this->email,
'IsTrial' => $this->istrial,
'Product' => $this->product,
'TechnicalProductLevel' => $this->technicallevel
];
}
}
4 changes: 2 additions & 2 deletions lib/Http/LicenseHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class LicenseHttpClient {
protected $baseUrl;

//public function __construct(IClientService $clientService, LoggerInterface $logger, string $baseUrl = "https://api.scwcloud.sendent.nl/") {
public function __construct(IClientService $clientService, LoggerInterface $logger, string $baseUrl = "https://api.scwcloud.sendent.dev/") {
//public function __construct(IClientService $clientService, LoggerInterface $logger, string $baseUrl = "http://127.0.0.1:8085/") {
public function __construct(IClientService $clientService, LoggerInterface $logger, string $baseUrl = "https://api.scwcloud.sendent.dev/") {
//public function __construct(IClientService $clientService, LoggerInterface $logger, string $baseUrl = "http://127.0.0.1:8085/") {
$this->client = $clientService->newClient();
$this->logger = $logger;
$this->baseUrl = $baseUrl;
Expand Down
10 changes: 10 additions & 0 deletions lib/Http/SubscriptionValidationHttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public function validate(License $licenseData, $connectedUserCount = null): ?Lic
$validatedLicense->setSubscriptionstatus($result->subscriptionStatus);
$validatedLicense->setMaxgraceusers($result->amountUsersMax);
$validatedLicense->setDatelastchecked(date_format(date_create("now"), "Y-m-d"));
$validatedLicense->setIstrial($result->isTrial);
$validatedLicense->setTechnicallevel($result->technicalProductLevel);
$validatedLicense->setProduct($result->product);


$this->logger->info('SUBSCRIPTIONVALIDATIONHTTPCLIENT-LEVEL= ' . $result->level);
$this->logger->info('SUBSCRIPTIONVALIDATIONHTTPCLIENT-KEY= ' . $result->key);
Expand All @@ -72,6 +76,9 @@ public function validate(License $licenseData, $connectedUserCount = null): ?Lic
{
$validatedLicense->setLevel(License::ERROR_VALIDATING);
$validatedLicense->setSubscriptionstatus(License::ERROR_VALIDATING);
$validatedLicense->setIstrial(-1);
$validatedLicense->setTechnicallevel(License::ERROR_VALIDATING);
$validatedLicense->setProduct(License::ERROR_VALIDATING);
error_log(print_r("SUBSCRIPTIONVALIDATIONHTTPCLIENT-VALIDATE SETTING LEVEL TO ERROR_VALIDATING", true));

}
Expand All @@ -82,6 +89,9 @@ public function validate(License $licenseData, $connectedUserCount = null): ?Lic
error_log(print_r('SUBSCRIPTIONVALIDATIONHTTPCLIENT-VALIDATE-EXCEPTION: ' . $e->getMessage(), true));
$validatedLicense->setSubscriptionstatus(License::ERROR_VALIDATING);
$validatedLicense->setLevel(License::ERROR_VALIDATING);
$validatedLicense->setIstrial(-1);
$validatedLicense->setTechnicallevel(License::ERROR_VALIDATING);
$validatedLicense->setProduct(License::ERROR_VALIDATING);
}

return $validatedLicense;
Expand Down
93 changes: 93 additions & 0 deletions lib/Migration/Version000020Date20231209100000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2022 Your name <[email protected]>
*
* @author Your name <[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/>.
*
*/

namespace OCA\Sendent\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version000020Date20231209100000 extends SimpleMigrationStep {

/** @var IDBConnection */
private $db;

public function __construct(IDBConnection $db) {
$this->db = $db;
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if ($schema->hasTable('sndnt_license')) {
// Adds a column to store the license used by a connected user
$table = $schema->getTable('sndnt_license');

$table->addColumn('product', \OCP\DB\Types::STRING, [
'notnull' => false,
'default' => 'undetermined'
]);
$table->addColumn('technicallevel', \OCP\DB\Types::STRING, [
'notnull' => false,
'default' => 'undetermined'
]);
$table->addColumn('istrial', \OCP\DB\Types::INTEGER, [
'notnull' => false,
'default' => -1
]);

}


return $schema;
}

/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
*/
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {

}
}
Loading

0 comments on commit e26b7c0

Please sign in to comment.