Merge pull request #15 from getsentry/fix-redmine
fix(redmine): Handle required fields
This commit is contained in:
commit
86029fba72
|
@ -1,5 +1,6 @@
|
|||
from __future__ import absolute_import
|
||||
import json
|
||||
import six
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -112,20 +113,20 @@ class RedminePlugin(IssuePlugin):
|
|||
'help':'Your API key is available on your account page after enabling the Rest API (Administration -> Settings -> Authentication)',
|
||||
'required':True,}
|
||||
project_id = {'name':'project_id',
|
||||
'label':'Project',
|
||||
'label':'Project*',
|
||||
'type':'select',
|
||||
'choices':[],
|
||||
'required':True,}
|
||||
'required':False,}
|
||||
tracker_id = {'name':'tracker_id',
|
||||
'label':'Tracker',
|
||||
'label':'Tracker*',
|
||||
'type':'select',
|
||||
'choices':[],
|
||||
'required':True,}
|
||||
'required':False,}
|
||||
default_priority = {'name':'default_priority',
|
||||
'label':'Default Priority',
|
||||
'label':'Default Priority*',
|
||||
'type':'select',
|
||||
'choices':[],
|
||||
'required':True,}
|
||||
'required':False,}
|
||||
extra_fields = {'name':'extra_fields',
|
||||
'label':'Extra Fields',
|
||||
'type':'text',
|
||||
|
@ -205,18 +206,25 @@ class RedminePlugin(IssuePlugin):
|
|||
for p in priorities['issue_priorities']
|
||||
]
|
||||
self.add_choices('default_priority', tracker_choices, choices_value)
|
||||
|
||||
if not has_credentials and not kwargs.get('add_additial_fields'):
|
||||
for field_name in ['project_id', 'tracker_id', 'default_priority']:
|
||||
|
||||
if not has_credentials:
|
||||
for field_name in ['project_id', 'tracker_id', 'default_priority', 'extra_fields']:
|
||||
self.remove_field(field_name)
|
||||
|
||||
|
||||
return self.fields
|
||||
|
||||
|
||||
|
||||
def validate_config(self, project, config, actor):
|
||||
super(RedminePlugin, self).validate_config(project, config, actor)
|
||||
self.client_errors = []
|
||||
|
||||
for field in self.fields:
|
||||
if field['name'] in ['project_id', 'tracker_id', 'default_priority']:
|
||||
if not config[field['name']]:
|
||||
self.logger.exception(six.text_type('{} required.'.format(field['name'])))
|
||||
self.client_errors.append(field['name'])
|
||||
|
||||
if self.client_errors:
|
||||
self.reset_options(project=project)
|
||||
raise PluginError(self.client_errors[0])
|
||||
raise PluginError(', '.join(self.client_errors) + ' required.')
|
||||
return config
|
||||
|
||||
|
|
Reference in New Issue