|
|
@@ -70,12 +70,25 @@ class Invites extends Organizr
|
|
|
|
|
|
public function _invitesPluginGetCodes()
|
|
|
{
|
|
|
- $response = [
|
|
|
- array(
|
|
|
- 'function' => 'fetchAll',
|
|
|
- 'query' => 'SELECT * FROM invites'
|
|
|
- )
|
|
|
- ];
|
|
|
+ if ($this->qualifyRequest(1, false)) {
|
|
|
+ $response = [
|
|
|
+ array(
|
|
|
+ 'function' => 'fetchAll',
|
|
|
+ 'query' => 'SELECT * FROM invites'
|
|
|
+ )
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $response = [
|
|
|
+ array(
|
|
|
+ 'function' => 'fetchAll',
|
|
|
+ 'query' => array (
|
|
|
+ 'SELECT * FROM invites WHERE invitedby = ?',
|
|
|
+ $this->user['username']
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
return $this->processQueries($response);
|
|
|
}
|
|
|
|
|
|
@@ -84,6 +97,14 @@ class Invites extends Organizr
|
|
|
$code = ($array['code']) ?? null;
|
|
|
$username = ($array['username']) ?? null;
|
|
|
$email = ($array['email']) ?? null;
|
|
|
+ $invites = $this->_invitesPluginGetCodes();
|
|
|
+ $inviteCount = count($invites);
|
|
|
+ if (!$this->qualifyRequest(1, false)) {
|
|
|
+ if ($this->config['INVITES-maximum-invites'] != 0 && $inviteCount >= $this->config['INVITES-maximum-invites']) {
|
|
|
+ $this->setAPIResponse('error', 'Maximum number of invites reached', 409);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
if (!$code) {
|
|
|
$this->setAPIResponse('error', 'Code not supplied', 409);
|
|
|
return false;
|
|
|
@@ -102,6 +123,7 @@ class Invites extends Organizr
|
|
|
'username' => $username,
|
|
|
'valid' => 'Yes',
|
|
|
'type' => $this->config['INVITES-type-include'],
|
|
|
+ 'invitedby' => $this->user['username'],
|
|
|
];
|
|
|
$response = [
|
|
|
array(
|
|
|
@@ -163,15 +185,33 @@ class Invites extends Organizr
|
|
|
|
|
|
public function _invitesPluginDeleteCode($code)
|
|
|
{
|
|
|
- $response = [
|
|
|
- array(
|
|
|
- 'function' => 'fetch',
|
|
|
- 'query' => array(
|
|
|
- 'SELECT * FROM invites WHERE code = ? COLLATE NOCASE',
|
|
|
- $code
|
|
|
+ if ($this->qualifyRequest(1, false)) {
|
|
|
+ $response = [
|
|
|
+ array(
|
|
|
+ 'function' => 'fetch',
|
|
|
+ 'query' => array(
|
|
|
+ 'SELECT * FROM invites WHERE code = ? COLLATE NOCASE',
|
|
|
+ $code
|
|
|
+ )
|
|
|
)
|
|
|
- )
|
|
|
- ];
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ if ($this->config['INVITES-allow-delete']) {
|
|
|
+ $response = [
|
|
|
+ array(
|
|
|
+ 'function' => 'fetch',
|
|
|
+ 'query' => array(
|
|
|
+ 'SELECT * FROM invites WHERE invitedby = ? AND code = ? COLLATE NOCASE',
|
|
|
+ $this->user['username'],
|
|
|
+ $code
|
|
|
+ )
|
|
|
+ )
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $this->setAPIResponse('error', 'You are not permitted to delete invites.', 409);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
$info = $this->processQueries($response);
|
|
|
if (!$info) {
|
|
|
$this->setAPIResponse('error', 'Code not found', 404);
|
|
|
@@ -308,7 +348,29 @@ class Invites extends Organizr
|
|
|
'value' => 'emby'
|
|
|
)
|
|
|
)
|
|
|
- )
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'type' => 'select',
|
|
|
+ 'name' => 'INVITES-Auth-include',
|
|
|
+ 'label' => 'Minimum Authentication',
|
|
|
+ 'value' => $this->config['INVITES-Auth-include'],
|
|
|
+ 'options' => $this->groupSelect()
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'type' => 'switch',
|
|
|
+ 'name' => 'INVITES-allow-delete-include',
|
|
|
+ 'label' => 'Allow users to delete invites',
|
|
|
+ 'help' => 'This must be disabled to enforce invitation limits.',
|
|
|
+ 'value' => $this->config['INVITES-allow-delete-include']
|
|
|
+ ),
|
|
|
+ array(
|
|
|
+ 'type' => 'number',
|
|
|
+ 'name' => 'INVITES-maximum-invites',
|
|
|
+ 'label' => 'Maximum number of invites permitted for users.',
|
|
|
+ 'help' => 'Set to 0 to disable the limit.',
|
|
|
+ 'value' => $this->config['INVITES-maximum-invites'],
|
|
|
+ 'placeholder' => '0'
|
|
|
+ ),
|
|
|
),
|
|
|
'Plex Settings' => array(
|
|
|
array(
|
|
|
@@ -533,5 +595,5 @@ class Invites extends Organizr
|
|
|
}
|
|
|
return (!empty($plexUser) ? $plexUser : null);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|