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

Updated new job composer project validation - Single Project Model #2990

Merged
merged 4 commits into from
Sep 7, 2023

Conversation

abujeda
Copy link
Contributor

@abujeda abujeda commented Aug 30, 2023

Fixes #2976

Updated project validation now that project directory can be configured by the user.
Draft PR to showcase approach for new project validation using create and update flows

@abujeda
Copy link
Contributor Author

abujeda commented Aug 30, 2023

I need to improve the tests if this approach goes in the right direction.

Comment on lines 148 to 152
if directory.to_s.include?(Project.dataroot.to_s)
FileUtils.remove_dir(project_dataroot, force = true)
else
FileUtils.remove_dir(configuration_directory, force = true)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we just want FileUtils.remove_dir(configuration_directory, true) and not what's in the if block right? I think deleting the entire directory would be an extra checkbox or similar as it may hold code, data and more.

Copy link
Contributor Author

@abujeda abujeda Aug 30, 2023

Choose a reason for hiding this comment

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

I think it makes sense to only delete the configuration_directory to avoid deleting scripts and outputs.
I kept the delete the project_dataroot as it was part of the original code.

An issue with no deleting project_dataroot is that ids are re-used so the same dir could be reused when deleting and creating projects. Which is not a good edge case.

Copy link
Contributor

Choose a reason for hiding this comment

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

An issue with no deleting project_dataroot is that ids are re-used so the same dir could be reused when deleting and creating projects. Which is not a good edge case.

Yea IDs need to change, I just hadn't filed the ticket yet - #2991

@johrstrom
Copy link
Contributor

I like this better than before - reviewing it I can see we're all over the place in terms of who knows what (controller now needing to set_defaults) and how things are done (projects_controller#create has to call projects#new, projects#create and project#save).

I'm going to hack around and see if there's something simpler because there just has to be.

@johrstrom
Copy link
Contributor

Yea the more I look at this the less I like what we're doing. Can I ask that you pick something else up and let me take care of this? Looking through git blame - we did not take great care around the directory and now there's a lot of cruft surrounding it (like project_dataroot - how is that different from self.directory? looks like it's just a bit wrong).

@abujeda
Copy link
Contributor Author

abujeda commented Aug 30, 2023

OK - will look for something else in the backlog

@johrstrom
Copy link
Contributor

OK - will look for something else in the backlog

Sorry for the back and forth - I just needed to do this myself to see what's what. You can continue on this pull request if you like. Here are my comments after doing this myself from scratch (from master)

  • ActiveModel validations are great. We should use them instead of the other methods
  • I don't care for the additional #create and #set_defaults methods. Indeed I don't think the controller should be setting the id (as it is currently doing now). I put some extra logic in save given we know what that context is. I.e., it is for sure a brand new project, otherwise we'd be calling update.
  • I think a big issue we have is in #initialize. I think it should just react correctly given the different contexts (i.e., new project vs. updating an existing one).

Here's the diff I was hacking around on. It has a few more updates than are strictly required but we're sort of doing different things in different spots that we need to clean up.

diff.txt

@abujeda
Copy link
Contributor Author

abujeda commented Aug 31, 2023

I had a look at your approach and made some changes locally for validation.
One thing that does not work with this approach, and the reason I had 2 different set of validations in the PR, is that when a new request comes in. We add the default values, then we validate. On validation errors, we render the form again. In this case, the directory and icon will be populated with the default values (if none provided initially by the user). This is not a good UX. The same will happen if there is a value, then is cleared. The default will come back.

Not quite sure how to fix this issue.
This is why I had initially the project_request object and then the :create and :update validations

@johrstrom
Copy link
Contributor

In this case, the directory and icon will be populated with the default values (if none provided initially by the user). This is not a good UX. The same will happen if there is a value, then is cleared. The default will come back.

Yea I noticed that too. I think we can set @dir=nil in the #save's else block (likely set the id back to nil as well) or in an https://apidock.com/rails/ActiveModel/Validations/Callbacks/ClassMethods/after_validation ?

@abujeda
Copy link
Contributor Author

abujeda commented Aug 31, 2023

I have made some changes based on your patch.
Still using validation based on the method that was called.
This could be replaced with conditional validation based on the new method: new_record?

else
FileUtils.remove_dir(configuration_directory, force = true)
end
FileUtils.remove_dir(configuration_directory, force = true)
Copy link
Contributor

Choose a reason for hiding this comment

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

IDK what your dev environment looks like - but you should use solargraph (I use the extension for VS Code).

It'll tell you simple mistakes like this:

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

I use RubyMine. Will check if this plugin, or similar, is available

Copy link
Contributor

Choose a reason for hiding this comment

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

yea really it's just a rubocop rule, solargraph is just the language server. Looks like jetbrains has support for it.

There's a .rubocop.yml at the top level of this project with a rake task to copy it to a more local directory (if you're like me and just open the apps/dashboard directory instead of the entire project).

@abujeda
Copy link
Contributor Author

abujeda commented Sep 6, 2023

@johrstrom if the general approach for the PR is going in the right direction, I can continue working on the tests.

I haven't fix them as I wasn't sure you were ok with the solution.

@johrstrom
Copy link
Contributor

@johrstrom if the general approach for the PR is going in the right direction, I can continue working on the tests.

I haven't fix them as I wasn't sure you were ok with the solution.

Sorry I didn't realize you were held up by me. Yes I think this is the right approach.

@abujeda abujeda force-pushed the 2976_project_validation_single_model branch from 37a5df7 to f4ac483 Compare September 6, 2023 18:55
Copy link
Contributor

@johrstrom johrstrom left a comment

Choose a reason for hiding this comment

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

Works for me, thanks!

@johrstrom johrstrom merged commit 63ffad9 into OSC:master Sep 7, 2023
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add some safety around where projects can be made
3 participants