'Remove a role from the system.
@param role_id: the ID or UID of the role
@note: protected roles cannot be deleted with this function,
need to reset the protected-flag first to override'

def s3_delete_role(self, role_id):

    db = current.db
    table = self.settings.table_group
    if (isinstance(role_id, str) and (not role_id.isdigit())):
        query = (table.uuid == role_id)
    else:
        role_id = int(role_id)
        query = (table.id == role_id)
    role = db(query).select(table.id, table.protected, limitby=(0, 1)).first()
    if (role and (not role.protected)):
        group_id = role.id
        data = {'deleted': True, 'group_id': None, 'deleted_fk': ('{"group_id":    %s}' % group_id)}
        mtable = self.settings.table_membership
        db((mtable.group_id == group_id)).update(**data)
        ptable = self.permission.table
        db((ptable.group_id == group_id)).update(**data)
        role.update_record(role=None, deleted=True)
