fix issues browsing when redmine requires an authenticity_token

This commit is contained in:
Romain Bignon 2011-07-12 16:34:47 +02:00
commit 4194875214
2 changed files with 32 additions and 18 deletions

View file

@ -44,6 +44,7 @@ class RedmineBrowser(BaseBrowser):
'https?://[^/]+/projects/([\w-]+)/wiki/([^\/]+)/edit': WikiEditPage,
'https?://[^/]+/projects/[\w-]+/wiki/[^\/]*': WikiPage,
'https?://[^/]+/projects/[\w-]+/issues/new': NewIssuePage,
'https?://[^/]+/projects/[\w-]+/issues': IssuesPage,
'https?://[^/]+/issues(|/?\?.*)': IssuesPage,
'https?://[^/]+/issues/(\d+)': IssuePage,
}
@ -107,8 +108,11 @@ class RedmineBrowser(BaseBrowser):
return lxml.html.tostring(preview_html)
def query_issues(self, project_name, **kwargs):
self.location('/projects/%s/issues' % project_name)
token = self.page.get_authenticity_token()
data = (('project_id', project_name),
('query[column_names][]', 'tracker'),
('authenticity_token', token),
('query[column_names][]', 'status'),
('query[column_names][]', 'priority'),
('query[column_names][]', 'subject'),

View file

@ -29,18 +29,26 @@ from weboob.tools.mech import ClientForm
class BaseIssuePage(BasePage):
def parse_datetime(self, text):
m = re.match('(\d+)/(\d+)/(\d+) (\d+):(\d+) (\w+)', text)
if not m:
self.logger.warning('Unable to parse "%s"' % text)
return text
if m:
date = datetime.datetime(int(m.group(3)),
int(m.group(1)),
int(m.group(2)),
int(m.group(4)),
int(m.group(5)))
if m.group(6) == 'pm':
date += datetime.timedelta(0,12*3600)
return date
date = datetime.datetime(int(m.group(3)),
int(m.group(1)),
int(m.group(2)),
int(m.group(4)),
int(m.group(5)))
if m.group(6) == 'pm':
date += datetime.timedelta(0,12*3600)
return date
m = re.match('(\d+)-(\d+)-(\d+) (\d+):(\d+)', text)
if m:
return datetime.datetime(int(m.group(1)),
int(m.group(2)),
int(m.group(3)),
int(m.group(4)),
int(m.group(5)))
self.logger.warning('Unable to parse "%s"' % text)
return text
PROJECT_FIELDS = {'members': 'values_assigned_to_id',
'categories': 'values_category_id',
@ -64,6 +72,14 @@ class BaseIssuePage(BasePage):
project[field] = list(self.iter_choices(elid))
return project
def get_authenticity_token(self):
tokens = self.parser.select(self.document.getroot(), 'input[name=authenticity_token]')
if len(tokens) == 0:
raise IssueError("You doesn't have rights to remove this issue.")
token = tokens[0].attrib['value']
return token
class IssuesPage(BaseIssuePage):
PROJECT_FIELDS = {'members': 'values_assigned_to_id',
'categories': 'values_category_id',
@ -243,10 +259,4 @@ class IssuePage(NewIssuePage):
return params
def get_authenticity_token(self):
tokens = self.parser.select(self.document.getroot(), 'input[name=authenticity_token]')
if len(tokens) == 0:
raise IssueError("You doesn't have rights to remove this issue.")
token = tokens[0].attrib['value']
return token