Beispiel #1
0
    def delete(self, relation_id, when=None):
        if when is None:
            when = datetime.now(utc)
        relation = Relation.load_by_relation_id(self.env, relation_id)
        source = relation.source
        destination = relation.destination
        relation_type = relation.type
        with self.env.db_transaction:
            cloned_relation = relation.clone()
            relation.delete()
            other_end = self.link_ends_map[relation_type]
            if other_end:
                reverted_relation = Relation(self.env,
                                             keys=dict(
                                                 source=destination,
                                                 destination=source,
                                                 type=other_end,
                                             ))
                reverted_relation.delete()

            for listener in self.changing_listeners:
                listener.deleting_relation(cloned_relation, when)

            from bhrelations.notification import RelationNotifyEmail
            RelationNotifyEmail(self.env).notify(cloned_relation, deleted=when)
Beispiel #2
0
 def delete_resource_relations(self, resource_instance):
     sql = "DELETE FROM " + Relation.get_table_name() + \
           " WHERE source=%s OR destination=%s"
     full_resource_id = ResourceIdSerializer.get_resource_id_from_instance(
         self.env, resource_instance)
     with self.env.db_transaction as db:
         db(sql, (full_resource_id, full_resource_id))
Beispiel #3
0
 def delete_resource_relations(self, resource_instance):
     sql = "DELETE FROM " + Relation.get_table_name() + \
           " WHERE source=%s OR destination=%s"
     full_resource_id = ResourceIdSerializer.get_resource_id_from_instance(
         self.env, resource_instance)
     with self.env.db_transaction as db:
         db(sql, (full_resource_id, full_resource_id))
Beispiel #4
0
 def _select_relations(self, source, resource_type=None):
     #todo: add optional paging for possible umbrella tickets with
     #a lot of child tickets
     where = dict(source=source)
     if resource_type:
         where["type"] = resource_type
         order_by = ["destination"]
     else:
         order_by = ["type", "destination"]
     return Relation.select(self.env, where=where, order_by=order_by)
Beispiel #5
0
 def remove_relations(self, req, rellist):
     relsys = RelationsSystem(self.env)
     for relid in rellist:
         relation = Relation.load_by_relation_id(self.env, relid)
         resource = ResourceIdSerializer.get_resource_by_id(
             relation.destination)
         if 'TICKET_MODIFY' in req.perm(resource):
             relsys.delete(relid)
         else:
             add_warning(req,
                 _('Not enough permissions to remove relation "%s"' % relid))
Beispiel #6
0
 def remove_relations(self, req, rellist):
     relsys = RelationsSystem(self.env)
     for relid in rellist:
         relation = Relation.load_by_relation_id(self.env, relid)
         resource = \
             ResourceIdSerializer.get_resource_by_id(relation.destination)
         if 'TICKET_MODIFY' in req.perm(resource):
             relsys.delete(relid)
         else:
             add_warning(req, _('Insufficient permissions to remove '
                                'relation "%(relation)s"', relation=relid))
Beispiel #7
0
    def delete(self, relation_id, when=None):
        if when is None:
            when = datetime.now(utc)
        relation = Relation.load_by_relation_id(self.env, relation_id)
        source = relation.source
        destination = relation.destination
        relation_type = relation.type
        with self.env.db_transaction:
            cloned_relation = relation.clone()
            relation.delete()
            other_end = self.link_ends_map[relation_type]
            if other_end:
                reverted_relation = Relation(self.env, keys=dict(
                    source=destination,
                    destination=source,
                    type=other_end,
                ))
                reverted_relation.delete()

            for listener in self.changing_listeners:
                listener.deleting_relation(cloned_relation, when)

            from bhrelations.notification import RelationNotifyEmail
            RelationNotifyEmail(self.env).notify(cloned_relation, deleted=when)
Beispiel #8
0
 def _select_relations(
         self, source, resource_type=None):
     #todo: add optional paging for possible umbrella tickets with
     #a lot of child tickets
     where = dict(source=source)
     if resource_type:
         where["type"] = resource_type
         order_by = ["destination"]
     else:
         order_by = ["type", "destination"]
     return Relation.select(
         self.env,
         where=where,
         order_by=order_by
     )
Beispiel #9
0
 def add(self,
         source_resource_instance,
         destination_resource_instance,
         relation_type,
         comment=None,
         author=None,
         when=None):
     source = ResourceIdSerializer.get_resource_id_from_instance(
         self.env, source_resource_instance)
     destination = ResourceIdSerializer.get_resource_id_from_instance(
         self.env, destination_resource_instance)
     if relation_type not in self.link_ends_map:
         raise UnknownRelationType(relation_type)
     if when is None:
         when = datetime.now(utc)
     relation = Relation(self.env)
     relation.source = source
     relation.destination = destination
     relation.type = relation_type
     relation.comment = comment
     relation.author = author
     relation.when = when
     self.add_relation(relation)
     return relation
Beispiel #10
0
 def add(self,
         source_resource_instance,
         destination_resource_instance,
         relation_type,
         comment=None,
         author=None,
         when=None):
     source = ResourceIdSerializer.get_resource_id_from_instance(
         self.env, source_resource_instance)
     destination = ResourceIdSerializer.get_resource_id_from_instance(
         self.env, destination_resource_instance)
     if relation_type not in self.link_ends_map:
         raise UnknownRelationType(relation_type)
     if when is None:
         when = datetime.now(utc)
     relation = Relation(self.env)
     relation.source = source
     relation.destination = destination
     relation.type = relation_type
     relation.comment = comment
     relation.author = author
     relation.when = when
     self.add_relation(relation)
     return relation