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

destroy dependent account objects #493

Merged
merged 1 commit into from Feb 10, 2016
Merged

destroy dependent account objects #493

merged 1 commit into from Feb 10, 2016

Conversation

tilsammans
Copy link
Contributor

themings and folders must not be orphaned, because they will break the UI in some ways.

I don't know if you like this spec style, I can do it differently, but this is what I usually do.

account = create(:account)
create(:folder, account: account)

expect {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using {...} for multi-line blocks.

@tilsammans
Copy link
Contributor Author

@tf your input is appreciated ... the test fails likely because i added a default theming name. however it's a required field and without a valid theming name default my new feature won't pass test either. It seems to me that default is a fine name for the default theming, especially since it validates against the array set in Pageflow config. Help?

@tf
Copy link
Member

tf commented Feb 9, 2016

The failing test submits an account form without theme_name as an example of invalid attributes. The default value turns that into a valid request.

I checked out your branch and your added tests also passed without this line since the default theming created in the account factory already has a theme name or am I missing something?

Two minor nitpicks:

  • Should we use dependent: :delete_all for the folders? There could potentially be many and they are so simple that it might not be worth deleting each in a separate query.
  • change(Pageflow::Theming, :count) could be change(Theming, :count) (or maybe even change { Theming.count } - but that's just a matter of taste) since we already are in the Pageflow modules.

EDIT: Feel free to ignore the rest of this comment

There is one bigger issue which I just came to realize: Admins can change entries to use a theming that is associated with a different account. While it has been handy in the past to test new themes without moving entries between accounts, it is something we have to be aware of now when we are deleting themings.

For accounts we prevent deletion as long as entries or users are associated. We could do something similar for themings. That would probably require some hints in the UI.

All other solutions I can think of seem counter intuitive to me:

  • Move the used theming to another account?
  • Reset the entry's themings to the account's default theme?
  • ?

The optimal solution from my point of view would be to display a disabled delete button with some sort of tooltip explaining why the account cannot be removed yet, instead of simply hiding the button the way we do at the moment. What do you think?

Sorry for turning this into a much bigger thing. I'll be happy to help once we've settled on a solution.

@tf
Copy link
Member

tf commented Feb 9, 2016

On second thought, maybe all of this makes things too complicated.

The main use case for changing an entry's theming instead of its account has been to change its theme while still giving the same group of users access. This will become much easier when I start working on allowing users to be members of multiple accounts next week. So as long as there is no real support for multiple themings per account, we should probably simply remove the theming drop down from the entry form.

So for the sake of this PR, we can simply assume that there are no more entries using an account's themings once the account is deleted. That way there will only be errors if you configured entries in special way instead of every time you delete an account.

Sorry for the wall of text.

@tilsammans
Copy link
Contributor Author

Should we use dependent: :delete_all for the folders?

I feel safer with :destroy since that will fire callbacks.

change(Pageflow::Theming, :count) could be change(Theming, :count)

Updated!

With regards to the rest of your comment, I agree it should be done in principle but if you're already planning on working this in the short term, I suppose it's a lot of work for not a lot of gain. And then keeping the scope of this PR small makes me happier; especially since it will plug a known usability issue.

PR updated.

@tf
Copy link
Member

tf commented Feb 10, 2016

Agreed! Please squash the commits and we're good to merge.

@tf
Copy link
Member

tf commented Feb 10, 2016

Could you take a second look at the commit message. It still talks about default theme naming etc...

Account destroy did not get rid of the associated theming. There is no
dependent: :destroy on the relation.

This is problematic because in the Edit Entry screen, a list of themings
is needed for the theming dropdown. When a theming does not have a
corresponding account, line 23 raises undefined method 'name' for
nil:NilClass.

The same holds for an account's folders.

fixes #476
@tilsammans
Copy link
Contributor Author

@tf all done

tf added a commit that referenced this pull request Feb 10, 2016
…destroy

destroy dependent account objects
@tf tf merged commit 85c45b1 into codevise:master Feb 10, 2016
@tf
Copy link
Member

tf commented Feb 10, 2016

👍

@tf tf added the bug label Feb 10, 2016
@tf tf added this to the v0.10 milestone Feb 10, 2016
@tilsammans tilsammans deleted the tilsammans/account-dependent-destroy branch February 10, 2016 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants