|
5 | 5 | #
|
6 | 6 | # The full license is in the file LICENSE, distributed with this software.
|
7 | 7 | # -----------------------------------------------------------------------------
|
8 |
| -from os.path import join, basename |
| 8 | +from os.path import join |
9 | 9 | from functools import partial
|
10 | 10 | from json import dumps
|
11 | 11 |
|
|
28 | 28 | PREP_TEMPLATE_KEY_FORMAT = 'prep_template_%s'
|
29 | 29 |
|
30 | 30 |
|
31 |
| -def artifact_summary_get_request(user_id, artifact_id): |
32 |
| - """Returns the information for the artifact summary page |
33 |
| -
|
34 |
| - Parameters |
35 |
| - ---------- |
36 |
| - user_id : str |
37 |
| - The user making the request |
38 |
| - artifact_id : int or str |
39 |
| - The artifact id |
40 |
| -
|
41 |
| - Returns |
42 |
| - ------- |
43 |
| - dict of objects |
44 |
| - A dictionary containing the artifact summary information |
45 |
| - {'status': str, |
46 |
| - 'message': str, |
47 |
| - 'name': str, |
48 |
| - 'summary': str, |
49 |
| - 'job': list of [str, str, str]} |
50 |
| - """ |
51 |
| - artifact_id = int(artifact_id) |
52 |
| - artifact = Artifact(artifact_id) |
53 |
| - |
54 |
| - access_error = check_access(artifact.study.id, user_id) |
55 |
| - if access_error: |
56 |
| - return access_error |
57 |
| - |
58 |
| - user = User(user_id) |
59 |
| - visibility = artifact.visibility |
60 |
| - summary = artifact.html_summary_fp |
61 |
| - job_info = None |
62 |
| - errored_jobs = [] |
63 |
| - processing_jobs = [] |
64 |
| - for j in artifact.jobs(): |
65 |
| - if j.command.software.type == "artifact transformation": |
66 |
| - status = j.status |
67 |
| - if status == 'success': |
68 |
| - continue |
69 |
| - j_msg = j.log.msg if status == 'error' else None |
70 |
| - processing_jobs.append( |
71 |
| - [j.id, j.command.name, j.status, j.step, j_msg]) |
72 |
| - |
73 |
| - # Check if the HTML summary exists |
74 |
| - if summary: |
75 |
| - with open(summary[1]) as f: |
76 |
| - summary = f.read() |
77 |
| - else: |
78 |
| - # Check if the summary is being generated |
79 |
| - command = Command.get_html_generator(artifact.artifact_type) |
80 |
| - all_jobs = set(artifact.jobs(cmd=command)) |
81 |
| - jobs = [j for j in all_jobs if j.status in ['queued', 'running']] |
82 |
| - errored_jobs = [(j.id, j.log.msg) |
83 |
| - for j in all_jobs if j.status in ['error']] |
84 |
| - if jobs: |
85 |
| - # There is already a job generating the HTML. Also, there should be |
86 |
| - # at most one job, because we are not allowing here to start more |
87 |
| - # than one |
88 |
| - job = jobs[0] |
89 |
| - job_info = [job.id, job.status, job.step] |
90 |
| - |
91 |
| - buttons = [] |
92 |
| - btn_base = ( |
93 |
| - '<button onclick="if (confirm(\'Are you sure you want to %s ' |
94 |
| - 'artifact id: {0}?\')) {{ set_artifact_visibility(\'%s\', {0}) }}" ' |
95 |
| - 'class="btn btn-primary btn-sm">%s</button>').format(artifact_id) |
96 |
| - |
97 |
| - if qiita_config.require_approval: |
98 |
| - if visibility == 'sandbox': |
99 |
| - # The request approval button only appears if the artifact is |
100 |
| - # sandboxed and the qiita_config specifies that the approval should |
101 |
| - # be requested |
102 |
| - buttons.append( |
103 |
| - btn_base % ('request approval for', 'awaiting_approval', |
104 |
| - 'Request approval')) |
105 |
| - |
106 |
| - elif user.level == 'admin' and visibility == 'awaiting_approval': |
107 |
| - # The approve artifact button only appears if the user is an admin |
108 |
| - # the artifact is waiting to be approvaed and the qiita config |
109 |
| - # requires artifact approval |
110 |
| - buttons.append(btn_base % ('approve', 'private', |
111 |
| - 'Approve artifact')) |
112 |
| - |
113 |
| - if visibility == 'private': |
114 |
| - # The make public button only appears if the artifact is private |
115 |
| - buttons.append(btn_base % ('make public', 'public', 'Make public')) |
116 |
| - |
117 |
| - # The revert to sandbox button only appears if the artifact is not |
118 |
| - # sandboxed nor public |
119 |
| - if visibility not in {'sandbox', 'public'}: |
120 |
| - buttons.append(btn_base % ('revert to sandbox', 'sandbox', |
121 |
| - 'Revert to sandbox')) |
122 |
| - |
123 |
| - if user.level == 'admin': |
124 |
| - if artifact.can_be_submitted_to_ebi: |
125 |
| - if not artifact.is_submitted_to_ebi: |
126 |
| - buttons.append( |
127 |
| - '<a class="btn btn-primary btn-sm" ' |
128 |
| - 'href="/ebi_submission/%d">' |
129 |
| - '<span class="glyphicon glyphicon-export"></span>' |
130 |
| - ' Submit to EBI</a>' % artifact_id) |
131 |
| - if artifact.can_be_submitted_to_vamps: |
132 |
| - if not artifact.is_submitted_to_vamps: |
133 |
| - buttons.append( |
134 |
| - '<a class="btn btn-primary btn-sm" href="/vamps/%d">' |
135 |
| - '<span class="glyphicon glyphicon-export"></span>' |
136 |
| - ' Submit to VAMPS</a>' % artifact_id) |
137 |
| - |
138 |
| - files = [(f_id, "%s (%s)" % (basename(fp), f_type.replace('_', ' '))) |
139 |
| - for f_id, fp, f_type in artifact.filepaths |
140 |
| - if f_type != 'directory'] |
141 |
| - |
142 |
| - # TODO: https://github.com/biocore/qiita/issues/1724 Remove this hardcoded |
143 |
| - # values to actually get the information from the database once it stores |
144 |
| - # the information |
145 |
| - if artifact.artifact_type in ['SFF', 'FASTQ', 'FASTA', 'FASTA_Sanger', |
146 |
| - 'per_sample_FASTQ']: |
147 |
| - # If the artifact is one of the "raw" types, only the owner of the |
148 |
| - # study and users that has been shared with can see the files |
149 |
| - if not artifact.study.has_access(user, no_public=True): |
150 |
| - files = [] |
151 |
| - |
152 |
| - processing_parameters = (artifact.processing_parameters.values |
153 |
| - if artifact.processing_parameters is not None |
154 |
| - else {}) |
155 |
| - |
156 |
| - return {'status': 'success', |
157 |
| - 'message': '', |
158 |
| - 'name': artifact.name, |
159 |
| - 'summary': summary, |
160 |
| - 'job': job_info, |
161 |
| - 'errored_jobs': errored_jobs, |
162 |
| - 'processing_jobs': processing_jobs, |
163 |
| - 'visibility': visibility, |
164 |
| - 'buttons': ' '.join(buttons), |
165 |
| - 'files': files, |
166 |
| - 'editable': artifact.study.can_edit(user), |
167 |
| - 'study_id': artifact.study.id, |
168 |
| - 'prep_id': artifact.prep_templates[0].id, |
169 |
| - 'processing_parameters': processing_parameters} |
170 |
| - |
171 |
| - |
172 |
| -def artifact_summary_post_request(user_id, artifact_id): |
173 |
| - """Launches the HTML summary generation and returns the job information |
174 |
| -
|
175 |
| - Parameters |
176 |
| - ---------- |
177 |
| - user_id : str |
178 |
| - The user making the request |
179 |
| - artifact_id : int or str |
180 |
| - The artifact id |
181 |
| -
|
182 |
| - Returns |
183 |
| - ------- |
184 |
| - dict of objects |
185 |
| - A dictionary containing the artifact summary information |
186 |
| - {'status': str, |
187 |
| - 'message': str, |
188 |
| - 'job': list of [str, str, str]} |
189 |
| - """ |
190 |
| - artifact_id = int(artifact_id) |
191 |
| - artifact = Artifact(artifact_id) |
192 |
| - |
193 |
| - access_error = check_access(artifact.study.id, user_id) |
194 |
| - if access_error: |
195 |
| - return access_error |
196 |
| - |
197 |
| - # Check if the summary is being generated or has been already generated |
198 |
| - command = Command.get_html_generator(artifact.artifact_type) |
199 |
| - jobs = artifact.jobs(cmd=command) |
200 |
| - jobs = [j for j in jobs if j.status in ['queued', 'running', 'success']] |
201 |
| - if jobs: |
202 |
| - # The HTML summary is either being generated or already generated. |
203 |
| - # Return the information of that job so we only generate the HTML |
204 |
| - # once |
205 |
| - job = jobs[0] |
206 |
| - else: |
207 |
| - # Create a new job to generate the HTML summary and return the newly |
208 |
| - # created job information |
209 |
| - job = ProcessingJob.create( |
210 |
| - User(user_id), |
211 |
| - Parameters.load(command, values_dict={'input_data': artifact_id})) |
212 |
| - job.submit() |
213 |
| - |
214 |
| - return {'status': 'success', |
215 |
| - 'message': '', |
216 |
| - 'job': [job.id, job.status, job.step]} |
217 |
| - |
218 |
| - |
219 | 31 | def artifact_get_req(user_id, artifact_id):
|
220 | 32 | """Returns all base information about an artifact
|
221 | 33 |
|
|
0 commit comments