Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Apr 1, 2021
2 parents bd205d4 + 5c382a7 commit 9a667ec
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 65 deletions.
22 changes: 20 additions & 2 deletions front/authorization.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,30 @@
include ('../../../inc/includes.php');

$authorization = new PluginOauthimapAuthorization();
$application = new PluginOauthimapApplication();

if (isset($_POST['id']) && isset($_POST['delete'])) {
$authorization->check($_POST['id'], DELETE);
$authorization->delete($_POST);

Html::back();
}
} else if (isset($_POST['id']) && isset($_POST['update'])) {
$authorization->check($_POST['id'], UPDATE);
if ($authorization->update($_POST)
&& $application->getFromDB($authorization->fields[$application->getForeignKeyField()])) {
Html::redirect($application->getLinkURL());
}

Html::displayErrorAndDie('lost');
Html::back();
} else if (isset($_GET['id'])) {
$application = new PluginOauthimapApplication();
$application->displayHeader();
$authorization->display(
[
'id' => $_GET['id'],
]
);
Html::footer();
} else {
Html::displayErrorAndDie('lost');
}
47 changes: 45 additions & 2 deletions inc/authorization.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

class PluginOauthimapAuthorization extends CommonDBChild {

// From CommonGlpi
protected $displaylist = false;

// From CommonDBTM
public $dohistory = true;

Expand Down Expand Up @@ -100,7 +103,7 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem
echo '<tr><th>' . __('No authorizations.', 'oauthimap') . '</th></tr>';
} else {
echo '<tr>';
echo '<th>' . __('Email') . '</th>';
echo '<th>' . __('Email', 'oauthimap') . '</th>';
echo '<th></th>';
echo '</tr>';

Expand All @@ -110,7 +113,11 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem
echo '<td>' . $row['email'] . '</td>';

echo '<td>';
echo '<form method="POST" action="' . Plugin::getWebDir('oauthimap') . '/front/authorization.form.php">';
echo '<a class="vsubmit" href="' . self::getFormURLWithID($row['id']) . '">';
echo __('Update', 'oauthimap');
echo '</a>';
echo ' ';
echo '<form method="POST" action="' . self::getFormURL() . '" style="display:inline-block;">';
echo Html::hidden('_glpi_csrf_token', ['value' => Session::getNewCSRFToken()]);
echo Html::hidden('id', ['value' => $row['id']]);
echo '<button type="submit" class="vsubmit" name="delete" value="1">';
Expand All @@ -129,6 +136,38 @@ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtem
return true;
}

public function showForm($id, $options = []) {

$options['colspan'] = 1;

$this->initForm($id, $options);
$this->showFormHeader($options);

echo '<tr class="tab_bg_1">';
echo '<td>';
echo __('Email', 'oauthimap');
echo ' ';
echo Html::showToolTip(
__('This email address corresponds to the "user" field of the SASL XOAUTH2 authentication query.'),
['display' => false]
);
echo '</td>';
echo '<td>';
echo Html::input(
'email',
[
'value' => $this->fields['email'],
'style' => 'width:90%'
]
);
echo '</td>';
echo '</tr>';

$this->showFormButtons($options + ['candel' => false]);

return true;
}

function prepareInputForAdd($input) {
if (!($input = $this->prepareInput($input))) {
return false;
Expand Down Expand Up @@ -292,6 +331,10 @@ public function getOwnerDetails(): ?OwnerDetails {
return $this->owner_details;
}

function post_updateItem($history = 1) {
MailCollectorFeature::postUpdateAuthorization($this);
parent::post_updateItem($history);
}

function post_purgeItem() {
MailCollectorFeature::postPurgeAuthorization($this);
Expand Down
31 changes: 31 additions & 0 deletions inc/mailcollectorfeature.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,37 @@ public static function postPurgeAuthorization(PluginOauthimapAuthorization $auth
);
}

/**
* Update mail collectors linked to the authorization.
*
* @param PluginOauthimapAuthorization $authorization
*
* @return void
*/
public static function postUpdateAuthorization(PluginOauthimapAuthorization $authorization): void {
if (in_array('email', $authorization->updates) && array_key_exists('email', $authorization->oldvalues)) {
$collectors = self::getAssociatedMailCollectors(
self::getMailProtocolTypeIdentifier($authorization->fields[PluginOauthimapApplication::getForeignKeyField()]),
$authorization->oldvalues['email']
);
foreach ($collectors as $row) {
$mailcollector = new MailCollector();
$mailcollector->update(
[
'id' => $row['id'],
'login' => $authorization->fields['email'],
]
);
Session::addMessageAfterRedirect(
sprintf(
__('Mail receiver "%s" has been updated.', 'oauthimap'),
$mailcollector->getName()
)
);
}
}
}

/**
* Deactivate mail collectors using given protocol type and given login.
*
Expand Down
Binary file modified locales/en_GB.mo
Binary file not shown.
41 changes: 25 additions & 16 deletions locales/en_GB.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# Cédric Anne, 2020
# Cédric Anne, 2021
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-10-14 13:17+0000\n"
"POT-Creation-Date: 2021-04-01 07:07+0000\n"
"PO-Revision-Date: 2020-10-15 13:49+0000\n"
"Last-Translator: Cédric Anne, 2020\n"
"Last-Translator: Cédric Anne, 2021\n"
"Language-Team: English (United Kingdom) (https://www.transifex.com/teclib/teams/28042/en_GB/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand All @@ -38,50 +38,59 @@ msgstr "Unable to get authorization code"
msgid "Unable to save authorization code"
msgstr "Unable to save authorization code"

#: inc/authorization.class.php:51
#: inc/authorization.class.php:54
msgid "Oauth authorization"
msgid_plural "Oauth authorizations"
msgstr[0] "Oauth authorization"
msgstr[1] "Oauth authorizations"

#: inc/authorization.class.php:92
#: inc/authorization.class.php:95
msgid "Create an authorization"
msgstr "Create an authorization"

#: inc/authorization.class.php:100
#: inc/authorization.class.php:103
msgid "No authorizations."
msgstr "No authorizations."

#: inc/authorization.class.php:104
msgid "Expires at"
msgstr "Expires at"
#: inc/authorization.class.php:106 inc/authorization.class.php:148
msgid "Email"
msgstr "Email"

#: inc/authorization.class.php:135
#: inc/authorization.class.php:117
msgid "Update"
msgstr "Update"

#: inc/authorization.class.php:125
msgid "Delete"
msgstr "Delete"

#: inc/mailcollectorfeature.class.php:360
#: inc/mailcollectorfeature.class.php:362
#, php-format
msgid "Mail receiver \"%s\" has been updated."
msgstr "Mail receiver \"%s\" has been updated."

#: inc/mailcollectorfeature.class.php:391
#, php-format
msgid "Mail receiver \"%s\" has been deactivated."
msgstr "Mail receiver \"%s\" has been deactivated."

#: inc/mailcollectorfeature.class.php:423
#: inc/mailcollectorfeature.class.php:454
msgid "No associated receivers."
msgstr "No associated receivers."

#: inc/mailcollectorfeature.class.php:426
#: inc/mailcollectorfeature.class.php:457
msgid "Name"
msgstr "Name"

#: inc/mailcollectorfeature.class.php:427
#: inc/mailcollectorfeature.class.php:458
msgid "Connection string"
msgstr "Connection string"

#: inc/mailcollectorfeature.class.php:428
#: inc/mailcollectorfeature.class.php:459
msgid "Login"
msgstr "Login"

#: inc/mailcollectorfeature.class.php:429
#: inc/mailcollectorfeature.class.php:460
msgid "Is active ?"
msgstr "Is active ?"

Expand Down
Binary file modified locales/fr_FR.mo
Binary file not shown.
41 changes: 25 additions & 16 deletions locales/fr_FR.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# Cédric Anne, 2020
# Cédric Anne, 2021
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-10-14 13:17+0000\n"
"POT-Creation-Date: 2021-04-01 07:07+0000\n"
"PO-Revision-Date: 2020-10-15 13:49+0000\n"
"Last-Translator: Cédric Anne, 2020\n"
"Last-Translator: Cédric Anne, 2021\n"
"Language-Team: French (France) (https://www.transifex.com/teclib/teams/28042/fr_FR/)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
Expand All @@ -38,50 +38,59 @@ msgstr "Impossible d'obtenir le code d'autorisation"
msgid "Unable to save authorization code"
msgstr "Impossible de sauvegarder le code d'autorisation"

#: inc/authorization.class.php:51
#: inc/authorization.class.php:54
msgid "Oauth authorization"
msgid_plural "Oauth authorizations"
msgstr[0] "Autorisation Oauth"
msgstr[1] "Autorisations Oauth"

#: inc/authorization.class.php:92
#: inc/authorization.class.php:95
msgid "Create an authorization"
msgstr "Créer une autorisation"

#: inc/authorization.class.php:100
#: inc/authorization.class.php:103
msgid "No authorizations."
msgstr "Aucune autorisation."

#: inc/authorization.class.php:104
msgid "Expires at"
msgstr "Date d'expiration"
#: inc/authorization.class.php:106 inc/authorization.class.php:148
msgid "Email"
msgstr "E-mail"

#: inc/authorization.class.php:135
#: inc/authorization.class.php:117
msgid "Update"
msgstr "Mettre à jour"

#: inc/authorization.class.php:125
msgid "Delete"
msgstr "Supprimer"

#: inc/mailcollectorfeature.class.php:360
#: inc/mailcollectorfeature.class.php:362
#, php-format
msgid "Mail receiver \"%s\" has been updated."
msgstr "Le collecteur mail \"%s\" a été mis à jour."

#: inc/mailcollectorfeature.class.php:391
#, php-format
msgid "Mail receiver \"%s\" has been deactivated."
msgstr "Le collecteur mail \"%s\" a été désactivé."

#: inc/mailcollectorfeature.class.php:423
#: inc/mailcollectorfeature.class.php:454
msgid "No associated receivers."
msgstr "Aucun collecteur associé."

#: inc/mailcollectorfeature.class.php:426
#: inc/mailcollectorfeature.class.php:457
msgid "Name"
msgstr "Nom"

#: inc/mailcollectorfeature.class.php:427
#: inc/mailcollectorfeature.class.php:458
msgid "Connection string"
msgstr "Chaîne de connexion"

#: inc/mailcollectorfeature.class.php:428
#: inc/mailcollectorfeature.class.php:459
msgid "Login"
msgstr "Identifiant"

#: inc/mailcollectorfeature.class.php:429
#: inc/mailcollectorfeature.class.php:460
msgid "Is active ?"
msgstr "Est actif ?"

Expand Down
Loading

0 comments on commit 9a667ec

Please sign in to comment.