Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "create drafts" permission #2923

Closed
colinmeinke opened this issue May 25, 2018 · 4 comments
Closed

Add "create drafts" permission #2923

colinmeinke opened this issue May 25, 2018 · 4 comments
Labels
enhancement improvements to existing features

Comments

@colinmeinke
Copy link

It would be nice to have a permission setting that allows a user to only create drafts.

Currently the nearest I can get to this is by checking "create entries" permission and keeping the "publish live changes" permission unchecked.

However, this allows users to:

  1. Create a draft
  2. Create a disabled entry

I am working on a site that requires strict control over entry versions (we fetch and display each version on the front-end). Creating a disabled entry also adds a row to the entryversions table. This means when this entry is enabled (by somebody with permission) it now has two versions, when in reality the actual content only has been edited once. I think another discussion to be had here is should changing the enabled state of an entry add a new row to the entryversions table?

@brandonkelly
Copy link
Member

It’s not possible to create a draft without also creating an entry, so splitting off drafts as its own thing would be unenforceable.

That said I’ll look into the feasibility of avoiding creating new entry versions when a new entry is immediately saved to a draft, and also when nothing substantial changes. Not totally sure where the line should be on that though - e.g. if only the Post Date changes, should that qualify as a new version?

@colinmeinke
Copy link
Author

@brandonkelly I think it would make sense to not trigger a new entry version for changes to any of the data in the right hand column:

  • Slug
  • Author
  • Post date
  • Expiry date
  • Enabled

@brandonkelly brandonkelly added the enhancement improvements to existing features label Jun 1, 2018
@brandonkelly
Copy link
Member

I’ve just made a change that will at least prevent new versions from being created when absolutely nothing changes.

I think it would make sense to not trigger a new entry version for changes to any of the data in the right hand column:

Not sure I agree. As long as Craft is remembering the complete state of an entry in its version data, then any change to that state should probably be stored.

That said, I’ve made it possible for you to alter the behavior, by placing the revision comparison check in its own protected function:

protected function compareRevisionData(array $revisionA, array $revisionB): bool
{
return $revisionA !== $revisionB;
}

If you want to only store new revisions when the custom fields change, then you can create a new class that extends craft\services\EntryRevisions and overrides that method, by placing this code in your config/app.php file:

<?php

class MyEntryRevisions extends craft\services\EntryRevisions
{
    protected function compareRevisionData(array $revisionA, array $revisionB): bool
    {
        return $revisionA['fields'] !== $revisionB['fields'];
    }
}

return [
    'components' => [
        'entryRevisions' => [
            'class' => MyEntryRevisions::class,
        ],
    ],
];

@colinmeinke
Copy link
Author

Great, thanks Brandon. I'm looking forward to this being released 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement improvements to existing features
Projects
None yet
Development

No branches or pull requests

2 participants