-
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 4 commits
7062548
9bca1b2
934a2fc
0d2b0fe
5a31c92
28fa47f
463fc20
62aa0b8
c1ab282
deed11a
99eee99
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,7 +128,7 @@ def initialize(attributes = {}) | |
| @directory = attributes[:directory] | ||
| @directory = File.expand_path(@directory) unless @directory.blank? | ||
| @template = attributes[:template] | ||
|
|
||
| @group_owner = get_group_owner | ||
| return if new_record? | ||
|
|
||
| contents = File.read(manifest_path) | ||
|
|
@@ -166,6 +166,7 @@ def save | |
| def update(attributes) | ||
| update_attrs(attributes) | ||
|
|
||
| return false unless update_ownership(attributes) | ||
| return false unless valid?(:update) | ||
|
|
||
| store_manifest(:update) | ||
|
|
@@ -203,6 +204,23 @@ def remove_from_lookup | |
| false | ||
| end | ||
|
|
||
| def get_group_owner | ||
| if project_dataroot.grpowned? | ||
| Etc.getgrgid(project_dataroot.stat.gid).name | ||
| else | ||
| 'None' | ||
| end | ||
| end | ||
|
|
||
| def set_group_owner(group) | ||
| begin | ||
| FileUtils.chown(nil, Etc.getgrnam(group).gid, project_dataroot) | ||
| rescue StandardError => e | ||
| errors.add(:update, "Unable to modify group ownership with error #{e.class}:#{e.message}") | ||
| false | ||
| end | ||
| end | ||
|
|
||
| def icon_class | ||
| # rails will prepopulate the tag with fa- so just the name is needed | ||
| icon.sub('fas://', '') | ||
|
|
@@ -299,6 +317,15 @@ def update_attrs(attributes) | |
| end | ||
| end | ||
|
|
||
| def update_ownership(attributes) | ||
| new_group = attributes.fetch(:group_owner, false) | ||
| if new_group | ||
| (new_group == 'None') ? true : set_group_owner(new_group) | ||
| else | ||
| true | ||
| end | ||
| end | ||
|
||
|
|
||
| def make_dir | ||
| project_dataroot.mkpath unless project_dataroot.exist? | ||
| configuration_directory.mkpath unless configuration_directory.exist? | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this instance variable is not explicitly used, it is responsible for setting the initial value in the form