def save_privileges(request):
  result = {'status': -1, 'message': 'Error'}

  try:
    role = json.loads(request.POST['role'])

    new_privileges = [privilege for privilege in role['privilegesChanged'] if privilege['status'] == 'new']
    result['privileges'] = _hive_add_privileges(request.user, role, new_privileges)

    deleted_privileges = [privilege for privilege in role['privilegesChanged'] if privilege['status'] == 'deleted']
    for privilege in deleted_privileges:
      _drop_sentry_privilege(request.user, role, privilege)

    modified_privileges = [privilege for privilege in role['privilegesChanged'] if privilege['status'] == 'modified']
    old_privileges_ids = [privilege['id'] for privilege in modified_privileges]
    _hive_add_privileges(request.user, role, modified_privileges)
    for privilege in role['originalPrivileges']:
      if privilege['id'] in old_privileges_ids:
        _drop_sentry_privilege(request.user, role, privilege)

    result['message'] = _('Privileges updated')
    result['status'] = 0
  except Exception, e:
    LOG.exception("could not save privileges")

    result['message'] = unicode(str(e), "utf8")

  return JsonResponse(result)
dataset/ETHPy150Open cloudera/hue/apps/security/src/security/api/hive.py/save_privileges/original