# HG changeset patch # User gga # Date 1535722396 14400 # Node ID 1a2976c6b1615b3923c125a8409a05a166f8fcd4 # Parent 9968eec7430e073140bc56b02629cc5521819a38 planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/apollo commit 85194fa009ead2c34720faab61a4143fc29d17c2 diff -r 9968eec7430e -r 1a2976c6b161 create_account.py --- a/create_account.py Mon Mar 12 06:30:56 2018 -0400 +++ b/create_account.py Fri Aug 31 09:33:16 2018 -0400 @@ -2,17 +2,11 @@ from __future__ import print_function import argparse -import random import time from six.moves.builtins import str -from webapollo import WAAuth, WebApolloInstance - - -def pwgen(length): - chars = list('qwrtpsdfghjklzxcvbnm') - return ''.join(random.choice(chars) for _ in range(length)) +from webapollo import PasswordGenerator, WAAuth, WebApolloInstance if __name__ == '__main__': @@ -26,7 +20,7 @@ wa = WebApolloInstance(args.apollo, args.username, args.password) - password = pwgen(12) + password = PasswordGenerator(12) time.sleep(1) users = wa.users.loadUsers() user = [u for u in users diff -r 9968eec7430e -r 1a2976c6b161 create_features_from_gff3.py --- a/create_features_from_gff3.py Mon Mar 12 06:30:56 2018 -0400 +++ b/create_features_from_gff3.py Fri Aug 31 09:33:16 2018 -0400 @@ -8,7 +8,7 @@ from six.moves.builtins import str -from webapollo import AssertUser, GuessOrg, OrgOrGuess, WAAuth, WebApolloInstance, featuresToFeatureSchema, retry +from webapollo import GuessOrg, OrgOrGuess, PermissionCheck, WAAuth, WebApolloInstance, featuresToFeatureSchema, retry logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) @@ -25,14 +25,15 @@ wa = WebApolloInstance(args.apollo, args.username, args.password) # User must have an account - gx_user = AssertUser(wa.users.loadUsers(email=args.email)) + gx_user = wa.users.assertOrCreateUser(args.email) # Get organism org_cn = GuessOrg(args, wa) if isinstance(org_cn, list): org_cn = org_cn[0] - # TODO: Check user perms on org. + if not PermissionCheck(gx_user, org_cn, "WRITE"): + raise Exception("Action not permitted") org = wa.organisms.findOrganismByCn(org_cn) bad_quals = ['date_creation', 'source', 'owner', 'date_last_modified', 'Name', 'ID'] diff -r 9968eec7430e -r 1a2976c6b161 create_or_update_organism.py --- a/create_or_update_organism.py Mon Mar 12 06:30:56 2018 -0400 +++ b/create_or_update_organism.py Fri Aug 31 09:33:16 2018 -0400 @@ -8,11 +8,10 @@ import sys import time -from webapollo import AssertUser, GuessOrg, OrgOrGuess, WAAuth, WebApolloInstance +from webapollo import GuessOrg, OrgOrGuess, PermissionCheck, WAAuth, WebApolloInstance logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) - if __name__ == '__main__': parser = argparse.ArgumentParser(description='Create or update an organism in an Apollo instance') WAAuth(parser) @@ -33,8 +32,8 @@ if isinstance(org_cn, list): org_cn = org_cn[0] - # User must have an account - gx_user = AssertUser(wa.users.loadUsers(email=args.email)) + # User must have an account, if not, create it + gx_user = wa.users.assertOrCreateUser(args.email) log.info("Determining if add or update required") try: @@ -43,14 +42,9 @@ org = None if org: - has_perms = False old_directory = org['directory'] - for user_owned_organism in gx_user.organismPermissions: - if 'WRITE' in user_owned_organism['permissions']: - has_perms = True - break - if not has_perms: + if not PermissionCheck(gx_user, org_cn, "WRITE"): print("Naming Conflict. You do not have permissions to access this organism. Either request permission from the owner, or choose a different name for your organism.") sys.exit(2) diff -r 9968eec7430e -r 1a2976c6b161 delete_features.py --- a/delete_features.py Mon Mar 12 06:30:56 2018 -0400 +++ b/delete_features.py Fri Aug 31 09:33:16 2018 -0400 @@ -5,7 +5,7 @@ import logging import random -from webapollo import AssertUser, GuessOrg, OrgOrGuess, WAAuth, WebApolloInstance, retry +from webapollo import GuessOrg, OrgOrGuess, PermissionCheck, WAAuth, WebApolloInstance, retry logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) @@ -21,14 +21,15 @@ wa = WebApolloInstance(args.apollo, args.username, args.password) # User must have an account - gx_user = AssertUser(wa.users.loadUsers(email=args.email)) + gx_user = wa.users.assertOrCreateUser(args.email) # Get organism org_cn = GuessOrg(args, wa) if isinstance(org_cn, list): org_cn = org_cn[0] - # TODO: Check user perms on org. + if not PermissionCheck(gx_user, org_cn, "WRITE"): + raise Exception("Action not permitted") org = wa.organisms.findOrganismByCn(org_cn) sequences = wa.organisms.getSequencesForOrganism(org['id']) diff -r 9968eec7430e -r 1a2976c6b161 delete_organism.py --- a/delete_organism.py Mon Mar 12 06:30:56 2018 -0400 +++ b/delete_organism.py Fri Aug 31 09:33:16 2018 -0400 @@ -4,7 +4,7 @@ import argparse import logging -from webapollo import AssertUser, GuessOrg, OrgOrGuess, WAAuth, WebApolloInstance +from webapollo import GuessOrg, OrgOrGuess, PermissionCheck, WAAuth, WebApolloInstance logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) @@ -19,14 +19,15 @@ wa = WebApolloInstance(args.apollo, args.username, args.password) # User must have an account - gx_user = AssertUser(wa.users.loadUsers(email=args.email)) + gx_user = wa.users.assertOrCreateUser(args.email) # Get organism org_cn = GuessOrg(args, wa) if isinstance(org_cn, list): org_cn = org_cn[0] - # TODO: Check user perms on org. + if not PermissionCheck(gx_user, org_cn, "WRITE"): + raise Exception("You do not have write permission on this organism") org = wa.organisms.findOrganismByCn(org_cn) # Call setSequence to tell apollo which organism we're working with @@ -34,7 +35,9 @@ # Then get a list of features. features = wa.annotations.getFeatures() # For each feature in the features - for feature in features['features']: - # We see that deleteFeatures wants a uniqueName, and so we pass - # is the uniquename field in the feature. - print(wa.annotations.deleteFeatures([feature['uniquename']])) + # If it exists + if 'features' in features: + for feature in features['features']: + # We see that deleteFeatures wants a uniqueName, and so we pass + # is the uniquename field in the feature. + print(wa.annotations.deleteFeatures([feature['uniquename']])) diff -r 9968eec7430e -r 1a2976c6b161 export.py --- a/export.py Mon Mar 12 06:30:56 2018 -0400 +++ b/export.py Fri Aug 31 09:33:16 2018 -0400 @@ -9,7 +9,7 @@ from Bio import SeqIO -from webapollo import CnOrGuess, GuessCn, WAAuth, WebApolloInstance +from webapollo import CnOrGuess, GuessCn, PermissionCheck, WAAuth, WebApolloInstance try: import StringIO as io @@ -71,15 +71,21 @@ parser.add_argument('--gff', type=argparse.FileType('w')) parser.add_argument('--fasta', type=argparse.FileType('w')) parser.add_argument('--json', type=argparse.FileType('w')) - + parser.add_argument('email', help='User Email') args = parser.parse_args() wa = WebApolloInstance(args.apollo, args.username, args.password) org_cn_list, seqs = GuessCn(args, wa) + # User must have an apollo account, if not, create it + gx_user = wa.users.assertOrCreateUser(args.email) + org_data = [] for org_cn in org_cn_list: + # User must have read permission on organism + if not PermissionCheck(gx_user, org_cn, "READ"): + continue indiv_org_data = export(org_cn, seqs) org_data.append(indiv_org_data) args.json.write(json.dumps(org_data, indent=2)) diff -r 9968eec7430e -r 1a2976c6b161 fetch_organism_jbrowse.py --- a/fetch_organism_jbrowse.py Mon Mar 12 06:30:56 2018 -0400 +++ b/fetch_organism_jbrowse.py Fri Aug 31 09:33:16 2018 -0400 @@ -9,7 +9,7 @@ import sys import time -from webapollo import GuessOrg, OrgOrGuess, WAAuth, WebApolloInstance +from webapollo import GuessOrg, OrgOrGuess, PermissionCheck, WAAuth, WebApolloInstance logging.basicConfig(level=logging.INFO) log = logging.getLogger(__name__) @@ -55,6 +55,7 @@ WAAuth(parser) OrgOrGuess(parser) parser.add_argument('target_dir', help='Target directory') + parser.add_argument('email', help='User Email') args = parser.parse_args() @@ -65,6 +66,14 @@ org_cn = org_cn[0] org = wa.organisms.findOrganismByCn(org_cn) + # User must have an account, if not, create it + gx_user = wa.users.assertOrCreateUser(args.email) + + # User must have READ access + + if not PermissionCheck(gx_user, org_cn, "READ"): + raise Exception("READ permissions are required for this action") + if not os.path.exists(args.target_dir): os.makedirs(args.target_dir) diff -r 9968eec7430e -r 1a2976c6b161 fetch_organism_jbrowse.xml --- a/fetch_organism_jbrowse.xml Mon Mar 12 06:30:56 2018 -0400 +++ b/fetch_organism_jbrowse.xml Fri Aug 31 09:33:16 2018 -0400 @@ -15,7 +15,9 @@ @ADMIN_AUTH@ @ORG_OR_GUESS@ -$jbrowse.files_path/ && +$jbrowse.files_path/ + +"$__user_email__" && cp $dummyIndex $jbrowse && find $jbrowse.files_path -type f -printf '