You are here

function blogapi_status_error_check in Blog API 7.2

Same name and namespace in other branches
  1. 7 blogapi.module \blogapi_status_error_check()

Check that the user has permission to save the node with the chosen status.

1 call to blogapi_status_error_check()
blogapi_submit_node in ./blogapi.module
Emulates node_form submission as services module does

File

./blogapi.module, line 406
Enable users to post using applications that support BlogAPIs.

Code

function blogapi_status_error_check($node) {
  $node = (object) $node;
  $original_status = $node->status;
  $node_type_default = variable_get('node_options_' . $node->type, array(
    'status',
    'promote',
  ));

  // If we don't have the 'administer nodes' permission and the status is
  // changing or for a new node the status is not the content type's default,
  // then return an error.
  if (!user_access('administer nodes') && ($node->status != $original_status || empty($node->nid) && $node->status != in_array('status', $node_type_default))) {
    if ($node->status) {
      return services_error(t('You do not have permission to publish this type of post. Please save it as a draft instead.'), 403);
    }
    else {
      return services_error(t('You do not have permission to save this post as a draft. Please publish it instead.'), 403);
    }
  }
}