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

Allow changing entry creator from the edit entry screen #2141

Conversation

doekenorg
Copy link
Contributor

@doekenorg doekenorg commented Sep 16, 2024

This PR addresses #721.

Export-1726495408919

💾 Build file (2cf7589).

- Add Created By (User) field to the edit screen
- Renders the field on the entry form
- Stores the value when the user has the correct rights
- Refactored to get original user from old entry data instead of post value
@zackkatz
Copy link
Member

@Mwalek Please take extra time to make sure that editing is only possible if a user has gravityforms_edit_entries, gravityview_edit_entries, and gform_full_access.

@Mwalek
Copy link

Mwalek commented Sep 25, 2024

@doekenorg there is a fatal error when editing an entry:

Fatal error: Uncaught Error: Class "GFExport" not found in /.../wp-content/plugins/gravityview/includes/class-gravityview-change-entry-creator.php:502

Steps to Reproduce

  1. Install and activate bc73aac
  2. Create a new View based on any form with existing entries
  3. In the Edit Entry Layout tab, add the "Created By (User)" field
  4. Open the View in the Front End
  5. Click any entry to open the single-entry layout
  6. Click the edit link

@mrcasual mrcasual assigned doekenorg and unassigned Mwalek Sep 26, 2024
@mrcasual
Copy link
Collaborator

mrcasual commented Oct 1, 2024

@doekenorg, was the critical error fixed by merging the develop branch? Please update the status.

@doekenorg
Copy link
Contributor Author

doekenorg commented Oct 1, 2024

@doekenorg, was the critical error fixed by merging the develop branch? Please update the status.

I mentioned to @Mwalek that I could not reproduce this. I don't understand where that mention is now gone. I feel like some updates are not persisted to Github very well; Or I'm dreaming about these things.

So @Mwalek please let me know if the latest version has this problem; and what the specs are. Because I cannot reproduce this scenario.

@Mwalek
Copy link

Mwalek commented Oct 2, 2024

@doekenorg the fatal error is still there. I set up a new site where I installed db39fd4 along with GravityForms 2.8.17. The site is running on PHP 8.3.

You can experience the error if you log in and click the edit button here:

https://gv-issue-721.try.gravitykit.com/view/eins/entry/1/ (test:test)

@doekenorg
Copy link
Contributor Author

@Mwalek fixed, please update to the last build and try again.

@Mwalek
Copy link

Mwalek commented Oct 2, 2024

Thanks @doekenorg, it's not crashing anymore. Will test the rest of the functionality now

@Mwalek
Copy link

Mwalek commented Oct 3, 2024

@zackkatz @doekenorg hopefully not missing something obvious, but is it expected that the single entry shows the admin (as author)? (see image)

Screenshot 2024-10-03 at 7 25 42 PM

Also, what are all the capabilities for users to edit the "created by" option?

I listed the capabilities for the admin role (wp cap list administrator) and the list did not include gravityforms_edit_entries or gform_full_access.

The output was as follows:

switch_themes
edit_themes
activate_plugins
edit_plugins
edit_users
edit_files
manage_options
moderate_comments
manage_categories
manage_links
upload_files
import
unfiltered_html
edit_posts
edit_others_posts
edit_published_posts
publish_posts
edit_pages
read
level_10
level_9
level_8
level_7
level_6
level_5
level_4
level_3
level_2
level_1
level_0
edit_others_pages
edit_published_pages
publish_pages
delete_pages
delete_others_pages
delete_published_pages
delete_posts
delete_others_posts
delete_published_posts
delete_private_posts
edit_private_posts
read_private_posts
delete_private_pages
edit_private_pages
read_private_pages
delete_users
create_users
unfiltered_upload
edit_dashboard
update_plugins
delete_plugins
install_plugins
update_themes
install_themes
update_core
list_users
remove_users
promote_users
edit_theme_options
delete_themes
export
gravityview_full_access
gravityview_view_settings
gravityview_edit_settings
gravityview_uninstall
gravityview_contact_support
edit_others_gravityviews
edit_private_gravityviews
edit_published_gravityviews
read_private_gravityviews
delete_private_gravityviews
delete_others_gravityviews
publish_gravityviews
delete_published_gravityviews
copy_gravityviews
gravityview_edit_others_entries
gravityview_moderate_entries
gravityview_delete_others_entries
gravityview_add_entry_notes
gravityview_view_entry_notes
gravityview_delete_entry_notes
gravityview_email_entry_notes
gravityview_edit_entries
gravityview_edit_entry
gravityview_edit_form_entries
gravityview_delete_entries
gravityview_delete_entry
edit_gravityviews
delete_gravityviews
gravityview_getting_started
gravityview_support_port
gravityview_view_entries
gravityview_view_others_entries

@rafaehlers
Copy link
Contributor

@zackkatz @doekenorg hopefully not missing something obvious, but is it expected that the single entry shows the admin (as author)?

That comes from the single.php template from your theme: https://docs.gravitykit.com/article/64-overriding-gravityview-templates (See the green notice)

Also, to your other question, please check: https://docs.gravitykit.com/article/311-gravityview-capabilities

@Mwalek
Copy link

Mwalek commented Oct 4, 2024

Thanks @rafaehlers! @zackkatz the permissions are okay. Users can only change the creator if they have the gravityforms_edit_entries capability listed here.

1. Custom Label Not Applied

  • Issue: In the Edit Entry Layout tab, the custom label of the "Created By (User)" field is not being used.
  • Expected Behavior: The custom label should appear as configured by the user.
  • Actual Behavior: The default label is displayed instead of the custom label.

2. "Show Label" Checkbox Not Functioning

  • Issue: In the Edit Entry Layout tab, the "Show Label" checkbox of the "Created By (User)" field does not work; the label is always shown.
  • Expected Behavior: When the "Show Label" checkbox is unchecked, the label should be hidden.
  • Actual Behavior: The label remains visible regardless of the checkbox setting.

3. Incorrect Label Name

  • Issue: The label incorrectly says "Created by (user id)" instead of "Created by (user)".
  • Expected Behavior: The label shown in the front end should appear as it does in the back end.
  • Actual Behavior: The label displays "Created by (user id)" in the front end, but "Created by (user)" in the back end.

4. Field Not Displayed When Empty

  • Issue: In the Single Entry Layout tab, when using the "User Format" option of the "Created by" field, if a field is not set, e.g. if the user "description" field is not set in the user's bio, the entire field is not shown.
  • Expected Behavior: An empty field with a label should still be shown even when the description is missing.
  • Actual Behavior: The entire field is hidden if the field is empty.

5. PHP Warning for Authors (map_meta_cap)

  • Issue: A PHP warning is triggered when logged in as an author and visiting a View with the "Created By" field in use:
    Notice: Function map_meta_cap was called incorrectly. When checking for the edit_post capability, you must always check it against a specific post. Please see Debugging in WordPress for more information. (This message was added in version 6.1.0.) in /.../public_html/wp-includes/functions.php on line 6085
    

6. AF Condition – Restricted View After Editing Entry

  • Issue: When using the Advanced Field (AF) settings, if the condition is set to display only entries created by a specific user, and the entry’s "created by" option of an entry is changed during front end editing, the user sees a message: "You are not allowed to view this content" upon returning to the entry.
  • Expected Behavior: After editing, the user should be able to return to the entry or be given an option to view all entries, avoiding confusion.
  • Actual Behavior: The user is restricted from viewing the entry they were editing and sees a restrictive message, with no easy navigation back to all entries.
  • Suggested Solution: Add a button on the restriction message page that allows the user to go back to the full list of entries, providing a smoother experience.

I also noticed that it's possible to add more than 1 "Created By" option in the Edit Entry Layout tab. This does not cause any issues because one of them is hidden in the front end, but it might help avoid some confusion for the user if it wasn't possible to add more than one "Created By" field in the first place.


Issue Summary

  • Custom label is not applied as configured.
  • "Show Label" checkbox does not hide the label when unchecked.
  • Label displays "Created by (user id)" instead of "Created by (user)".
  • Entire field is hidden when the chosen "User Format" data is empty.
  • PHP warning appears for authors: map_meta_cap function called incorrectly.
  • Users receive a "You are not allowed to view this content" message after changing the entry creator.

@mrcasual
Copy link
Collaborator

@doekenorg, over to you.

@doekenorg
Copy link
Contributor Author

doekenorg commented Oct 11, 2024

@Mwalek issue 4, 5 and 6 are not specific to this feature. They are issues that are already there, even without this PR.

For 4 and 5 I think we need separate issues. For 6 I'm not sure. This is expected behaviour. But a backlink might make sense; if it doesn't leak any sensitive information.

As for 1-3; those are fixed. Please test that. After that I think we can merge and release this @mrcasual .

Edit: Fixed 5 on this one.

@Mwalek
Copy link

Mwalek commented Oct 14, 2024

Thanks @doekenorg! I can confirm that issues 1, 2, 3, and 5 are resolved. I created a seperate issue #2167 for item number 4 (field not displayed when empty). I guess we can ignore number 6 since it's expected.

@doekenorg doekenorg assigned mrcasual and unassigned doekenorg and Mwalek Oct 14, 2024
@doekenorg
Copy link
Contributor Author

@mrcasual this is ready for release from my pov.

@mrcasual mrcasual merged commit d171c2e into develop Oct 14, 2024
1 check passed
@mrcasual mrcasual deleted the feature/721-allow-changing-entry-creator-from-the-edit-entry-screen branch October 14, 2024 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants