Ejemplo n.º 1
0
    def update(self, data, authz):
        self.label = data.get('label', self.label)
        self.summary = data.get('summary', self.summary)
        self.summary = data.get('summary', self.summary)
        self.publisher = data.get('publisher', self.publisher)
        self.publisher_url = data.get('publisher_url', self.publisher_url)
        self.info_url = data.get('info_url', self.info_url)
        self.data_url = data.get('data_url', self.data_url)
        self.countries = ensure_list(data.get('countries', self.countries))
        self.languages = ensure_list(data.get('languages', self.languages))

        # Some fields are editable only by admins in order to have
        # a strict separation between source evidence and case
        # material.
        if authz.is_admin:
            self.category = data.get('category', self.category)
            self.casefile = as_bool(data.get('casefile'),
                                    default=self.casefile)
            creator = Role.by_id(data.get('creator_id'))
            if creator is not None:
                self.creator = creator

        self.touch()
        db.session.flush()
        if self.creator is not None:
            Permission.grant(self, self.creator, True, True)
Ejemplo n.º 2
0
 def update_creator(self, role):
     """Set the creator (and admin) of a collection."""
     if not isinstance(role, Role):
         role = Role.by_id(role)
     if role is None or role.type != Role.USER:
         return
     self.creator = role
     db.session.add(self)
     db.session.flush()
     Permission.grant(self, role, True, True)
Ejemplo n.º 3
0
 def update(self, data, creator=None):
     self.label = data.get('label', self.label)
     self.summary = data.get('summary', self.summary)
     self.category = data.get('category', self.category)
     self.managed = data.get('managed', False)
     self.countries = data.get('countries', [])
     if creator is None:
         creator = Role.by_id(data.get('creator_id'))
     self.creator = creator
     self.updated_at = datetime.utcnow()
     db.session.add(self)
     db.session.flush()
     if creator is not None:
         Permission.grant(self, creator, True, True)
Ejemplo n.º 4
0
 def create(cls, data, authz, created_at=None):
     foreign_id = data.get("foreign_id") or make_textid()
     collection = cls.by_foreign_id(foreign_id, deleted=True)
     if collection is None:
         collection = cls()
         collection.created_at = created_at
         collection.foreign_id = foreign_id
         collection.category = cls.CASEFILE
         collection.creator = authz.role
     collection.update(data, authz)
     collection.deleted_at = None
     if collection.creator is not None:
         Permission.grant(collection, collection.creator, True, True)
     return collection
Ejemplo n.º 5
0
    def update(self, data, authz):
        self.label = data.get('label', self.label)
        self.summary = data.get('summary', self.summary)
        self.publisher = data.get('publisher', self.publisher)
        self.publisher_url = data.get('publisher_url', self.publisher_url)
        if self.publisher_url is not None:
            self.publisher_url = stringify(self.publisher_url)
        self.info_url = data.get('info_url', self.info_url)
        if self.info_url is not None:
            self.info_url = stringify(self.info_url)
        self.data_url = data.get('data_url', self.data_url)
        if self.data_url is not None:
            self.data_url = stringify(self.data_url)
        self.countries = ensure_list(data.get('countries', self.countries))
        self.countries = [
            registry.country.clean(val) for val in self.countries
        ]  # noqa
        self.languages = ensure_list(data.get('languages', self.languages))
        self.languages = [
            registry.language.clean(val) for val in self.languages
        ]  # noqa
        self.frequency = data.get('frequency', self.frequency)
        self.restricted = data.get('restricted', self.restricted)
        self.xref = data.get('xref', self.xref)

        # Some fields are editable only by admins in order to have
        # a strict separation between source evidence and case
        # material.
        if authz.is_admin:
            self.category = data.get('category', self.category)
            self.casefile = as_bool(data.get('casefile'),
                                    default=self.casefile)
            creator = ensure_dict(data.get('creator'))
            creator_id = data.get('creator_id', creator.get('id'))
            creator = Role.by_id(creator_id)
            if creator is not None:
                self.creator = creator

        if self.casefile:
            self.category = 'casefile'

        self.touch()
        db.session.flush()
        if self.creator is not None:
            Permission.grant(self, self.creator, True, True)
Ejemplo n.º 6
0
 def update(self, data, creator=None):
     self.label = data.get('label', self.label)
     self.summary = data.get('summary', self.summary)
     self.summary = data.get('summary', self.summary)
     self.publisher = data.get('publisher', self.publisher)
     self.publisher_url = data.get('publisher_url', self.publisher_url)
     self.info_url = data.get('info_url', self.info_url)
     self.data_url = data.get('data_url', self.data_url)
     self.category = data.get('category') or self.DEFAULT
     self.casefile = as_bool(data.get('casefile'), default=False)
     self.countries = data.get('countries', [])
     self.languages = data.get('languages', [])
     if creator is None:
         creator = Role.by_id(data.get('creator_id'))
     self.creator = creator
     self.updated_at = datetime.utcnow()
     db.session.add(self)
     db.session.flush()
     if creator is not None:
         Permission.grant(self, creator, True, True)
Ejemplo n.º 7
0
 def update(self, data, creator=None):
     self.label = data.get('label', self.label)
     self.summary = data.get('summary', self.summary)
     self.summary = data.get('summary', self.summary)
     self.publisher = data.get('publisher', self.publisher)
     self.publisher_url = data.get('publisher_url', self.publisher_url)
     self.info_url = data.get('info_url', self.info_url)
     self.data_url = data.get('data_url', self.data_url)
     self.category = data.get('category', self.category)
     self.casefile = as_bool(data.get('casefile'), default=self.casefile)
     self.countries = ensure_list(data.get('countries', self.countries))
     self.languages = ensure_list(data.get('languages', self.languages))
     if creator is None:
         creator = Role.by_id(data.get('creator_id'))
     if creator is not None:
         self.creator = creator
     self.touch()
     db.session.flush()
     if self.creator is not None:
         Permission.grant(self, self.creator, True, True)
Ejemplo n.º 8
0
 def update(self, data, creator=None):
     self.updated_at = datetime.utcnow()
     self.label = data.get('label', self.label)
     self.summary = data.get('summary', self.summary)
     self.summary = data.get('summary', self.summary)
     self.publisher = data.get('publisher', self.publisher)
     self.publisher_url = data.get('publisher_url', self.publisher_url)
     self.info_url = data.get('info_url', self.info_url)
     self.data_url = data.get('data_url', self.data_url)
     self.category = data.get('category', self.category)
     self.casefile = as_bool(data.get('casefile'), default=self.casefile)
     self.countries = ensure_list(data.get('countries', self.countries))
     self.languages = ensure_list(data.get('languages', self.languages))
     if creator is None:
         creator = Role.by_id(data.get('creator_id'))
     if creator is not None:
         self.creator = creator
     db.session.add(self)
     db.session.flush()
     if self.creator is not None:
         Permission.grant(self, self.creator, True, True)