Ejemplo n.º 1
0
 def process_comments(self, ticket, comments):
     for comment_json in comments:
         user = self.get_user(comment_json['author'])
         with h.push_config(c, user=user):
             p = ticket.discussion_thread.add_post(
                 text=self.annotate(comment_json['text'], user,
                                    comment_json['author']),
                 ignore_security=True,
                 timestamp=dateutil.parser.parse(comment_json['timestamp']),
             )
             p.add_multiple_attachments(
                 [File(a['url']) for a in comment_json['attachments']])
Ejemplo n.º 2
0
 def get_icon(self, project):
     page = self.get_page('project_info')
     icon_url = urljoin(self.url, page.find(itemprop='image').get('src'))
     if icon_url == self.DEFAULT_ICON:
         return
     icon_name = urllib.unquote(urlparse(icon_url).path).split('/')[-1]
     icon = File(icon_url, icon_name)
     M.ProjectFile.save_image(icon_name,
                              icon.file,
                              icon.type,
                              square=True,
                              thumbnail_size=(48, 48),
                              thumbnail_meta={
                                  'project_id': project._id,
                                  'category': 'icon'
                              })
Ejemplo n.º 3
0
 def get_icon(self, project):
     page = self.get_page('project_info')
     icon_url = urljoin(self.url, page.find(itemprop='image').get('src'))
     if icon_url == self.DEFAULT_ICON:
         return
     icon_name = urllib.unquote(urlparse(icon_url).path).split('/')[-1]
     icon = File(icon_url, icon_name)
     filetype = icon.type
     # work around Google Code giving us bogus file type
     if filetype.startswith('text/html'):
         filetype = 'image/png'
     M.ProjectFile.save_image(icon_name,
                              icon.file,
                              filetype,
                              square=True,
                              thumbnail_size=(48, 48),
                              thumbnail_meta={
                                  'project_id': project._id,
                                  'category': 'icon'
                              })
Ejemplo n.º 4
0
    def add_posts(self, thread, posts, app):
        created_posts = []

        for post_json in posts:
            username = post_json["author"]
            user = self.get_user(username)

            with h.push_config(c, user=user, app=app):
                timestamp = parse(post_json['timestamp'])

                # For nested posts
                parent_id = None
                slug = ''
                if "slug" in list(post_json.keys()):
                    slug = post_json["slug"]

                    if slug.count('/') >= 1:
                        pos = slug.rindex('/')
                        parent_slug = slug[:pos]

                        for cp in created_posts:
                            if cp.get(parent_slug, None) is not None:
                                parent_id = cp[parent_slug]._id
                                break

                p = thread.add_post(subject=post_json['subject'],
                                    text=self.annotate_text(
                                        post_json['text'], user, username),
                                    timestamp=timestamp,
                                    ignore_security=True,
                                    parent_id=parent_id)

                if ("last_edited" in post_json) and (post_json["last_edited"]
                                                     is not None):
                    p.last_edit_date = parse(post_json["last_edited"])

                p.add_multiple_attachments(
                    [File(a["url"]) for a in post_json["attachments"]])

                if slug != '':
                    created_posts.append({slug: p})
Ejemplo n.º 5
0
 def import_tool(self,
                 project,
                 user,
                 mount_point=None,
                 mount_label=None,
                 **kw):
     import_id_converter = ImportIdConverter.get()
     tracker_json = self._load_json(project)
     tracker_json['tracker_config']['options'].pop('ordinal', None)
     tracker_json['tracker_config']['options'].pop('mount_point', None)
     tracker_json['tracker_config']['options'].pop('mount_label', None)
     tracker_json['tracker_config']['options'].pop('import_id', None)
     app = project.install_app(
         'tickets',
         mount_point,
         mount_label,
         import_id={
             'source': self.source,
             'app_config_id': tracker_json['tracker_config']['_id'],
         },
         open_status_names=tracker_json['open_status_names'],
         closed_status_names=tracker_json['closed_status_names'],
         **tracker_json['tracker_config']['options'])
     ThreadLocalORMSession.flush_all()
     try:
         M.session.artifact_orm_session._get().skip_mod_date = True
         for ticket_json in tracker_json['tickets']:
             reporter = self.get_user(ticket_json['reported_by'])
             owner = self.get_user(ticket_json['assigned_to'])
             with h.push_config(c, user=reporter, app=app):
                 self.max_ticket_num = max(ticket_json['ticket_num'],
                                           self.max_ticket_num)
                 ticket = TM.Ticket(
                     app_config_id=app.config._id,
                     import_id=import_id_converter.expand(
                         ticket_json['ticket_num'], app),
                     description=self.annotate(self.annotate(
                         ticket_json['description'],
                         owner,
                         ticket_json['assigned_to'],
                         label=' owned'),
                                               reporter,
                                               ticket_json['reported_by'],
                                               label=' created'),
                     created_date=dateutil.parser.parse(
                         ticket_json['created_date']),
                     mod_date=dateutil.parser.parse(
                         ticket_json['mod_date']),
                     ticket_num=ticket_json['ticket_num'],
                     summary=ticket_json['summary'],
                     custom_fields=ticket_json['custom_fields'],
                     status=ticket_json['status'],
                     labels=ticket_json['labels'],
                     votes_down=ticket_json['votes_down'],
                     votes_up=ticket_json['votes_up'],
                     votes=ticket_json['votes_up'] -
                     ticket_json['votes_down'],
                     assigned_to_id=owner._id,
                 )
                 # add an attachment to the ticket
                 ticket.add_multiple_attachments(
                     [File(a['url']) for a in ticket_json['attachments']])
                 # trigger the private property
                 ticket.private = ticket_json['private']
                 self.process_comments(
                     ticket, ticket_json['discussion_thread']['posts'])
                 session(ticket).flush(ticket)
                 session(ticket).expunge(ticket)
         app.globals.custom_fields = tracker_json['custom_fields']
         self.process_bins(app, tracker_json['saved_bins'])
         app.globals.last_ticket_num = self.max_ticket_num
         M.AuditLog.log(
             'import tool %s from exported Allura JSON' %
             (app.config.options.mount_point, ),
             project=project,
             user=user,
             url=app.url,
         )
         g.post_event('project_updated')
         app.globals.invalidate_bin_counts()
         ThreadLocalORMSession.flush_all()
         return app
     except Exception:
         h.make_app_admin_only(app)
         raise
     finally:
         M.session.artifact_orm_session._get().skip_mod_date = False