moodle/moodle · error · moodle_exception
cannoteditentryorblog
Error message
cannoteditentryorblog
What it means
The blog external webservice function (update_entry) throws moodle_exception('cannoteditentryorblog','blog') when blog_user_can_edit_entry($entry) returns false, i.e. the current web-service user is not allowed to modify the given blog entry. The library treats edit rights as: the entry author, a user with moodle/blog:manageentries, or a user with moodle/blog:manageofficialentries for associated entries. It exists to enforce per-entry ownership rules inside the external API after the entryid has been resolved.
Solutions
- Log in as (or issue a token for) the user who authored the entry
- Grant the calling user's role the capability moodle/blog:manageentries at system context
- Verify the entryid belongs to the expected user via blog_get_entries before calling update
- Check role/capability overrides that may have removed blog capabilities for the service account
Example fix
// before
$entrydata->id = $entry->id; // throws cannoteditentryorblog for non-authors
// after
if (!blog_user_can_edit_entry($entry)) {
// ensure the WS user has manage capability, or pick an entry they own
throw new moodle_exception('cannoteditentryorblog', 'blog');
} Defensive patterns
Strategy: validation
Validate before calling
if (empty($CFG->enableblogs)) { throw new moodle_exception('blogdisable','blog'); }
$entry = new blog_entry($entryid);
if (empty($entry->id)) { /* wrongentryid: abort */ }
$canEdit = blog_user_can_edit_entry($entry); Type guard
function canEditBlogEntry(blog_entry $entry): bool {
return !empty($entry->id) && blog_user_can_edit_entry($entry);
} Try / catch
try {
blog_update_entry($entrydata);
} catch (moodle_exception $e) {
if ($e->errorcode === 'cannoteditentryorblog') {
// fall back: request manageentries or edit as the author
}
} Prevention
- Check blog_user_can_edit_entry before every external update call
- Issue web service tokens only for users who own the entries they modify
- Grant moodle/blog:manageentries to service/manager accounts that must edit any entry
- Keep entryid-to-owner mappings verified in your integration
When it happens
Trigger: Calling the blog_update_entry external function where $params['entryid'] resolves to a valid entry but the authenticated user is neither its author nor holds moodle/blog:manageentries (or manageofficialentries where applicable). Note the source also guards `if (!$entry = new \blog_entry(...))` which only triggers on wrongentryid; the cannotedit exception comes strictly from the permission check.
Common situations: A web service token belonging to a user who did not write the entry; an admin creates a token for a service account that lacks moodle/blog:manageentries; trying to edit another user's entry via the external API assuming admin-level rights; capability changed by role overrides after the token was issued.
Understand the failure class
Background: "You do not have permission" / 403 Forbidden errors: authenticated but not allowed — causes and fixes across open-source libraries — this error's family across 31 libraries.
Related errors
- cannoteditentryorblog
- cannoteditentryorblog
- nopermissionstodeleteentry
- blogdisable
- cannoteditentryorblog
AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14).
Data as JSON: /api/errors/788ea03472979def.
Report an issue: GitHub.
Appendix: source
Thrown at public/blog/classes/external/update_entry.php:100
array $options = []): array {
global $DB, $CFG;
require_once($CFG->dirroot . '/blog/lib.php');
require_once($CFG->dirroot . '/blog/locallib.php');
$params = self::validate_parameters(self::execute_parameters(), compact('entryid', 'subject', 'summary',
'summaryformat', 'options'));
if (empty($CFG->enableblogs)) {
throw new moodle_exception('blogdisable', 'blog');
}
if (!$entry = new \blog_entry($params['entryid'])) {
throw new moodle_exception('wrongentryid', 'blog');
}
if (!blog_user_can_edit_entry($entry)) {
throw new \moodle_exception('cannoteditentryorblog', 'blog');
}
// Prepare the entry object.
$entrydata = new \stdClass();
$entrydata->id = $entry->id;
$entrydata->subject = $params['subject'];
$entrydata->summary_editor = [
'text' => $params['summary'],
'format' => $params['summaryformat'],
];
$entrydata->publishstate = $entry->publishstate;
$entrydata->courseassoc = $entry->courseassoc;
$entrydata->modassoc = $entry->modassoc;
$entrydata->tags = \core_tag_tag::get_item_tags_array('core', 'post', $entry->id);
// Options.
foreach ($params['options'] as $option) {
$name = trim($option['name']);View on GitHub (pinned to 48ea8c3322)