Skip to content

Commit

Permalink
Merge pull request #1965 from josenavas/plugin-installation-update-keys
Browse files Browse the repository at this point in the history
Allowing updating the oauth2 info
  • Loading branch information
antgonza committed Sep 30, 2016
2 parents 1388858 + 432df2c commit 38f00e5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
26 changes: 22 additions & 4 deletions qiita_db/software.py
Expand Up @@ -579,10 +579,27 @@ def from_file(cls, fp, update=False):

if (client_id != instance.client_id or
client_secret != instance.client_secret):
raise qdb.exceptions.QiitaDBOperationNotPermittedError(
'The (client_id, client_secret) pair of the plugin '
'"%s" version "%s" does not match the one in the '
'system' % (name, version))
if update:
sql = """INSERT INTO qiita.oauth_identifiers
(client_id, client_secret)
SELECT %s, %s
WHERE NOT EXISTS(SELECT *
FROM qiita.oauth_identifiers
WHERE client_id = %s
AND client_secret = %s)"""
qdb.sql_connection.TRN.add(
sql, [client_id, client_secret,
client_id, client_secret])
sql = """UPDATE qiita.oauth_software
SET client_id = %s
WHERE software_id = %s"""
qdb.sql_connection.TRN.add(
sql, [client_id, instance.id])
else:
raise qdb.exceptions.QiitaDBOperationNotPermittedError(
'The (client_id, client_secret) pair of the '
'plugin "%s" version "%s" does not match the one '
'in the system' % (name, version))

if warning_values:
warnings.warn(
Expand All @@ -592,6 +609,7 @@ def from_file(cls, fp, update=False):
'information. Offending values: %s'
% (name, version, ", ".join(sorted(warning_values))),
qdb.exceptions.QiitaDBWarning)
qdb.sql_connection.TRN.execute()
else:
# This is a new plugin, create it
instance = cls.create(
Expand Down
19 changes: 11 additions & 8 deletions qiita_db/test/test_software.py
Expand Up @@ -503,17 +503,20 @@ def test_from_file(self):
self._clean_up_files.append(fp)
with open(fp, 'w') as f:
f.write(CONF_TEMPLATE %
('QIIME', '1.9.1',
'Quantitative Insights Into Microbial Ecology (QIIME) '
'is an open-source bioinformatics pipeline for '
'performing microbiome analysis from raw DNA '
'sequencing data', 'source activate qiita',
'start_target_gene', 'artifact transformation',
'[["10.1038/nmeth.f.303", "20383131"]]', "client_id",
client_secret))
('Target Gene type', '0.1.0',
'Target gene artifact types plugin',
'source activate qiita', 'start_target_gene_types',
'artifact definition', '', 'client_id', 'client_secret'))

with self.assertRaises(QE.QiitaDBOperationNotPermittedError):
qdb.software.Software.from_file(fp)

# But allow to update if update = True
obs = qdb.software.Software.from_file(fp, update=True)
self.assertEqual(obs, qdb.software.Software(3))
self.assertEqual(obs.client_id, 'client_id')
self.assertEqual(obs.client_secret, 'client_secret')

def test_exists(self):
self.assertTrue(qdb.software.Software.exists("QIIME", "1.9.1"))
self.assertFalse(qdb.software.Software.exists("NewPlugin", "1.9.1"))
Expand Down

0 comments on commit 38f00e5

Please sign in to comment.