-
Notifications
You must be signed in to change notification settings - Fork 162
Toggle group ownership on projects #4792
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
base: master
Are you sure you want to change the base?
Changes from all commits
7062548
9bca1b2
934a2fc
0d2b0fe
5a31c92
28fa47f
463fc20
62aa0b8
c1ab282
deed11a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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] | ||
|
|
@@ -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? | ||
|
|
||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since it's an |
||
| 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 | ||
|
|
@@ -305,6 +329,7 @@ def update_attrs(attributes) | |
|
|
||
| def make_dir | ||
| project_dataroot.mkpath unless project_dataroot.exist? | ||
| set_group_owner | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we actually move this to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I wonder if this prompts a reorganization to the setup steps here. Maybe we have a method |
||
| configuration_directory.mkpath unless configuration_directory.exist? | ||
| workflow_directory = Workflow.workflow_dir(project_dataroot) | ||
| workflow_directory.mkpath unless workflow_directory.exist? | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,29 @@ | |
| <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"> | ||
| <% help_html = unless edit_project_action | ||
| <<-HEREDOC | ||
| <a type="button" href="javascript:void(0)" data-bs-toggle="popover" data-bs-placement="right" aria-title="What group should I pick?" | ||
| data-bs-content="#{I18n.t('dashboard.jobs_project_group_help')}" class="mx-1 help-button"> | ||
| <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"> | ||
| <path d="M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14m0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16"/> | ||
| <path d="M5.255 5.786a.237.237 0 0 0 .241.247h.825c.138 0 .248-.113.266-.25.09-.656.54-1.134 1.342-1.134.686 0 1.314.343 1.314 1.168 0 .635-.374.927-.965 1.371-.673.489-1.206 1.06-1.168 1.987l.003.217a.25.25 0 0 0 .25.246h.811a.25.25 0 0 0 .25-.25v-.105c0-.718.273-.927 1.01-1.486.609-.463 1.244-.977 1.244-2.056 0-1.511-1.276-2.241-2.673-2.241-1.267 0-2.655.59-2.75 2.286m1.557 5.763c0 .533.425.927 1.01.927.609 0 1.028-.394 1.028-.927 0-.552-.42-.94-1.029-.94-.584 0-1.009.388-1.009.94"/> | ||
| </svg> | ||
| </a> | ||
| HEREDOC | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added the help button to the label by passing html as a HEREDOC string to the bootstrap-form helper. This html includes the question-circle bootstrap icon as an svg. If we do not like the idea of including the svg directly, there are other ways (like adding bootstrap-icons as a dependency), but this seems the most straightforward and stable. |
||
| else | ||
| '' | ||
| end | ||
| %> | ||
| <%= form.select(:group_owner, | ||
| CurrentUser.group_names, | ||
| { label: "#{I18n.t('dashboard.jobs_project_group_owner')} #{help_html}".html_safe }, | ||
| { disabled: edit_project_action }) | ||
| %> | ||
| </div> | ||
| <% end %> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.