Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/dashboard/app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def templates
def project_params
params
.require(:project)
.permit(:name, :directory, :description, :icon, :id, :template)
.permit(:name, :directory, :description, :icon, :id, :template, :group_owner)
end

def show_project_params
Expand Down
27 changes: 26 additions & 1 deletion apps/dashboard/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def importable_directories
end
end

attr_reader :id, :name, :description, :icon, :directory, :template, :files
attr_reader :id, :name, :description, :icon, :directory, :template, :files, :group_owner

validates :name, presence: { message: :required }, on: [:create, :update]
validates :id, :directory, :icon, presence: { message: :required }, on: [:update]
Expand All @@ -128,6 +128,7 @@ def initialize(attributes = {})
@directory = attributes[:directory]
@directory = File.expand_path(@directory) unless @directory.blank?
@template = attributes[:template]
@group_owner = attributes[:group_owner] || get_group_owner

return if new_record?

Expand Down Expand Up @@ -203,6 +204,29 @@ def remove_from_lookup
false
end

def private?
project_dataroot.to_s.start_with?(CurrentUser.home)
end

def get_group_owner
if project_dataroot != Project.dataroot && project_dataroot.grpowned?
Etc.getgrgid(project_dataroot.stat.gid).name
else
nil
end
end

def set_group_owner
return true if private? || @group_owner == get_group_owner
Copy link
Contributor

Choose a reason for hiding this comment

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

Since it's an att_reader we should prefer to use it instead of referencing the instance variable directly. I.e., group_owner instead of @group_owner.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also the name of this method implies it's a setter method, which it doesn't actually set the instance variable. Infact it's chowns the directory, not just retrieve an instance variable.

Can we fix these get_ and set_ signatures? Maybe it's more like default_group_owner and chown_directory respectively.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I definitely see how set is a problem with that. For get_group_owner I am less sure, seeing as this is the source of truth that we use to report it later (indeed it returns nil if run on an uninitialized project). 'Default' could also get confused with setgid bit (or other 'default' facl rules) so I would want a different term than that.

For set_group_owner, maybe we want to borrow some other naming patterns from this file and call it update_group_owner (in the pattern of update_permissions)? It cannot set the group to anything other than the group_owner attribute, and I feel like chown_directory may be missing that aspect.

I suppose in both cases there is an issue of ambiguity between the 'actual' group on the project root, and the @group_owner instance variable, and both methods are used to help get these in sync with one another.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, there's also chgrp_directory too.

As to get_group_owner maybe it's just directory_group_owner?

It's just get & set - on the surface - tend to reference getting and setting instance variables so I'd like to avoid them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok yeah I am happy with those

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have taken care of renaming the two methods and using the attr_reader instead of getting the variable directly

begin
group_gid = @group_owner.nil? ? nil : Etc.getgrnam(@group_owner).gid
FileUtils.chown(nil, group_gid, project_dataroot)
rescue StandardError => e
errors.add(:update, "Unable to set group ownership with error #{e.class}:#{e.message}")
false
end
end

def editable?
File.writable?(manifest_path)
end
Expand Down Expand Up @@ -305,6 +329,7 @@ def update_attrs(attributes)

def make_dir
project_dataroot.mkpath unless project_dataroot.exist?
set_group_owner
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we actually move this to update_permissons - I feel like it fits better there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Errr.... actually it is fine here. We should maybe just pass 750 to mkpath here.

I say that it's fine here, because we'll also need to setgid bit for shared projects and we should do that before we make the other directories so that they're initialized under the correct group.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It certainly would logically, but as soon as project_dataroot has files, we end up in the chmod -r scenario that could present a lot of complex cases. By intercepting it as soon as the project directory is created (before it has any contents) we make sure that the group ownership (and eventually setbit) setting can inform the creation of those project files

Copy link
Contributor Author

@Bubballoo3 Bubballoo3 Dec 5, 2025

Choose a reason for hiding this comment

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

We should maybe just pass 750 to mkpath here

I wonder if this prompts a reorganization to the setup steps here. Maybe we have a method make_root that just creates the root directory, and then fire them in the following order: make_root && update_permissions && make_dir.... That way all the permissions changes have the chance to apply before metadata files are created

Copy link
Contributor Author

@Bubballoo3 Bubballoo3 Dec 9, 2025

Choose a reason for hiding this comment

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

I decided to go ahead and make these changes. So the root directory creation has it's own method make_root, chgrp_directory is included in update_permissions, and the flow in save is as I described above. Since we are going to have the setbit stuff coming this sets us up ahead of time.

configuration_directory.mkpath unless configuration_directory.exist?
workflow_directory = Workflow.workflow_dir(project_dataroot)
workflow_directory.mkpath unless workflow_directory.exist?
Expand Down
8 changes: 8 additions & 0 deletions apps/dashboard/app/views/projects/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
<div class="field">
<%= form.text_area :description, placeholder: I18n.t('dashboard.jobs_project_description_placeholder') %>
</div>
<% unless @project.private? && edit_project_action %>
<div class="field">
<%= form.select(:group_owner,
CurrentUser.group_names,
{ label: I18n.t('dashboard.jobs_project_group_owner') },
{ disabled: edit_project_action })%>
</div>
<% end %>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ en:
jobs_project_directory_error: Project directory path is not set for this workflow
jobs_project_directory_placeholder: Project directory absolute path
jobs_project_generic_error: 'There was an error processing your request: %{error}'
jobs_project_group_owner: Group owner
jobs_project_invalid_configuration_clusters: An HPC cluster is required. Contact your administrator to add one to the system.
jobs_project_invalid_configuration_scripts: An executable script is required for your project. Upload a script using the file application.
jobs_project_job_deleted: Successfully deleted job %{job_id}
Expand Down
Loading