Ver Fonte

minor updates to invites

TehMuffinMoo há 4 anos atrás
pai
commit
dbbb5a50c0

+ 1 - 1
api/plugins/invites/api.php

@@ -371,7 +371,7 @@ $app->delete('/plugins/invites/{code}', function ($request, $response, $args) {
 	 */
 	 */
 	$Invites = new Invites();
 	$Invites = new Invites();
 	if ($Invites->checkRoute($request)) {
 	if ($Invites->checkRoute($request)) {
-		if ($Invites->qualifyRequest(1, true)) {
+		if ($Invites->qualifyRequest($Invites->config['INVITES-Auth-include'], true)) {
 			$Invites->_invitesPluginDeleteCode($args['code']);
 			$Invites->_invitesPluginDeleteCode($args['code']);
 		}
 		}
 	}
 	}

+ 0 - 9
api/plugins/invites/config.php

@@ -1,21 +1,12 @@
 <?php
 <?php
 return array(
 return array(
 	'INVITES-enabled' => false,
 	'INVITES-enabled' => false,
-<<<<<<< HEAD
 	'INVITES-Auth-include' => '1',
 	'INVITES-Auth-include' => '1',
-=======
 	'INVITES-dbVersion' => '1.0.0',
 	'INVITES-dbVersion' => '1.0.0',
->>>>>>> f55aabfda5bcf6310a08a759df52827747ae44a9
 	'INVITES-type-include' => 'plex',
 	'INVITES-type-include' => 'plex',
 	'INVITES-plexLibraries' => '',
 	'INVITES-plexLibraries' => '',
 	'INVITES-EmbyTemplate' => '',
 	'INVITES-EmbyTemplate' => '',
 	'INVITES-plex-tv-labels' => '',
 	'INVITES-plex-tv-labels' => '',
 	'INVITES-plex-music-labels' => '',
 	'INVITES-plex-music-labels' => '',
-<<<<<<< HEAD
-	'INVITES-plex-movies-labels' => '',
-	'INVITES-db-version' => '1.1'
-);
-=======
 	'INVITES-plex-movies-labels' => ''
 	'INVITES-plex-movies-labels' => ''
 );
 );
->>>>>>> f55aabfda5bcf6310a08a759df52827747ae44a9

+ 26 - 64
api/plugins/invites/plugin.php

@@ -78,11 +78,13 @@ class Invites extends Organizr
 				)
 				)
 			];
 			];
 		} else {
 		} else {
-			$query = 'SELECT * FROM invites WHERE invitedby="'.$this->user['username'].'";';
 			$response = [
 			$response = [
 				array(
 				array(
 					'function' => 'fetchAll',
 					'function' => 'fetchAll',
-					'query' => $query
+					'query' => array (
+						'SELECT * FROM invites WHERE invitedby = ?',
+						$this->user['username']
+					)
 				)
 				)
 			];
 			];
 		}
 		}
@@ -92,10 +94,6 @@ class Invites extends Organizr
 	
 	
 	public function _invitesPluginCreateCode($array)
 	public function _invitesPluginCreateCode($array)
 	{
 	{
-		if (!$this->_invitesPluginUpgradeDB()) {
-			$this->setAPIResponse('error', 'Invites Plugin - Error Upgrading Database', 409);
-			return $false;
-		}
 		$code = ($array['code']) ?? null;
 		$code = ($array['code']) ?? null;
 		$username = ($array['username']) ?? null;
 		$username = ($array['username']) ?? null;
 		$email = ($array['email']) ?? null;
 		$email = ($array['email']) ?? null;
@@ -179,18 +177,31 @@ class Invites extends Organizr
 	
 	
 	public function _invitesPluginDeleteCode($code)
 	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 {
+			$response = [
+				array(
+					'function' => 'fetch',
+					'query' => array(
+						'SELECT * FROM invites WHERE invitedby = ? AND code = ? COLLATE NOCASE',
+						$this->user['username'],
+						$code
+					)
+				)
+			];
+		}
 		$info = $this->processQueries($response);
 		$info = $this->processQueries($response);
 		if (!$info) {
 		if (!$info) {
-			$this->setAPIResponse('error', 'Code not found', 404);
+			$this->setAPIResponse('error', 'Code not found'.$response, 404);
 			return false;
 			return false;
 		}
 		}
 		$response = [
 		$response = [
@@ -557,53 +568,4 @@ class Invites extends Organizr
 		return (!empty($plexUser) ? $plexUser : null);
 		return (!empty($plexUser) ? $plexUser : null);
 	}
 	}
 
 
-	public function _invitesPluginUpgradeDB()
-	{
-		$DBVersion = "1.1";
-		if ($this->config['INVITES-db-version'] < $DBVersion) {
-			$response = [
-				array(
-					'function' => 'fetchAll',
-					'query' => 'PRAGMA table_info("invites")'
-				)
-			];
-			$sqlquery = $this->processQueries($response);
-			$key = array_search("invitedby", array_column($sqlquery, 'name'));
-			if (!$key) {
-				$sqlalterquery = [
-					array(
-						'function' => 'fetchAll',
-						'query' => 'ALTER TABLE invites ADD invitedby text;'
-					)
-				];
-				$sqlalter = $this->processQueries($sqlalterquery);
-				$sqlquery = $this->processQueries($response);
-				$key = array_search("invitedby", array_column($sqlquery, 'name'));
-				if ($key) {
-					$dbVersion = array (
-						"INVITES-db-version" => $DBVersion,
-					);
-					$this->updateConfigItems($dbVersion);
-					$this->setAPIResponse('success', 'Database upgraded successfully.', 200);
-					$this->writeLog('info', 'Invites Plugin - Database upgraded successfully.', 'SYSTEM');
-					return true;
-				} else {
-					$this->writeLog('error', 'Invites Plugin - Error Upgrading Database', 'SYSTEM');
-					$this->setAPIResponse('error', 'Invites Plugin - Error Upgrading Database', 409);
-					return false;
-				}
-			} else {
-				$dbVersion = array (
-					"INVITES-db-version" => $DBVersion,
-				);
-				$this->updateConfigItems($dbVersion);
-				$this->setAPIResponse('success', 'Database upgraded successfully.', 200);
-				return true;
-			}
-		} else {
-			$this->setAPIResponse('success', 'Database up to date.', 200);
-			return true;
-		}
-	}
-	
 }
 }