'Authorize the import of this item, sets self.permitted'

def authorize(self):

    if (not self.table):
        return False
    auth = current.auth
    tablename = self.tablename
    if ((not auth.override) and (tablename.split('_', 1)[0] in auth.PROTECTED)):
        return False
    METHOD = self.METHOD
    if (self.data.deleted is True):
        if self.data.deleted_rb:
            self.method = METHOD['MERGE']
        else:
            self.method = METHOD['DELETE']
        self.accepted = (True if self.id else False)
    elif self.id:
        if (not self.original):
            fields = S3Resource.import_fields(self.table, self.data, mandatory=self._mandatory_fields())
            query = (self.table.id == self.id)
            self.original = current.db(query).select(limitby=(0, 1), *fields).first()
        if self.original:
            self.method = METHOD['UPDATE']
        else:
            self.method = METHOD['CREATE']
    else:
        self.method = METHOD['CREATE']
    if (self.method == METHOD['CREATE']):
        self.id = 0
    authorize = current.auth.s3_has_permission
    if authorize:
        self.permitted = authorize(self.method, tablename, record_id=self.id)
    else:
        self.permitted = True
    return self.permitted
