-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #329 from yast/edit-y2users
Edit users
- Loading branch information
Showing
29 changed files
with
2,121 additions
and
501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Copyright (c) [2021] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "forwardable" | ||
|
||
module Y2Users | ||
# Base class for collections | ||
# | ||
# A collection is similar to a ruby Array class, but the collection is intended to provide query | ||
# methods to make easier to work with the collected elements. | ||
# | ||
# @example | ||
# # Collection of named elements (respond to #name method) | ||
# class ExampleCollection < Collection | ||
# def by_name(value) | ||
# selection = elements.select { |e| e.name == value } | ||
# | ||
# self.class.new(selection) | ||
# end | ||
# end | ||
# | ||
# obj1 = NamedObject.new("foo") | ||
# obj2 = NamedObject.new("bar") | ||
# obj3 = NamedObject.new("foo") | ||
# | ||
# collection = ExampleCollection.new([obj1, obj2, obj3]) | ||
# collection.by_name("foo") #=> ExampleCollection<obj1, obj3> | ||
# collection.empty? #=> false | ||
class Collection | ||
extend Forwardable | ||
|
||
def_delegators :@elements, :each, :select, :find, :reject, :map, :any?, :size, :empty?, :first | ||
|
||
# Constructor | ||
# | ||
# @param elements [Array<Object>] | ||
def initialize(elements = []) | ||
@elements = elements | ||
end | ||
|
||
# Adds an element to the collection | ||
# | ||
# @raise [FrozenError] see {#check_editable} | ||
# | ||
# @param element [Object] | ||
# @return [self] | ||
def add(element) | ||
check_editable | ||
|
||
@elements << element | ||
|
||
self | ||
end | ||
|
||
# List with all the elements | ||
# | ||
# @return [Array<Object>] | ||
def all | ||
@elements.dup | ||
end | ||
|
||
alias_method :to_a, :all | ||
|
||
# Generates a new collection with the sum of elements | ||
# | ||
# @param other [Collection] | ||
# @return [Collection] | ||
def +(other) | ||
self.class.new(all + other.all) | ||
end | ||
|
||
private | ||
|
||
# Checks whether the collection can be modified | ||
# | ||
# Modifications in the list of elements should be prevented when the collection is frozen. | ||
# | ||
# @raise [FrozenError] if the collection is frozen | ||
# @return [Boolean] | ||
def check_editable | ||
return true unless frozen? | ||
|
||
raise FrozenError, "can't modify frozen #{self.class}: #{inspect}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Copyright (c) [2021] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
module Y2Users | ||
# Class for configuring the commit action for a user | ||
# | ||
# Writers can receive a collection of objects of this class (see {CommitConfigCollection}) in | ||
# order to decide what actions to perform over the user. For example, a writer can use the commit | ||
# config to check whether the content of the home directory should be moved or not. | ||
class CommitConfig | ||
# Name of the user this commit config applies to | ||
# | ||
# @return [String] | ||
attr_accessor :username | ||
|
||
# Whether the home should be empty after the creation (i.e., do not use skels) | ||
# | ||
# @return [Boolean] | ||
attr_writer :home_without_skel | ||
|
||
# Whether to move the content of the current home directory to the new location | ||
# | ||
# @return [Boolean] | ||
attr_writer :move_home | ||
|
||
# Whether this user should own the home. This is useful when changing the home to reuse an | ||
# existing directory/subvolume. | ||
# | ||
# @return [Boolean] | ||
attr_writer :adapt_home_ownership | ||
|
||
# @return [Boolean] | ||
def home_without_skel? | ||
!!@home_without_skel | ||
end | ||
|
||
# @return [Boolean] | ||
def move_home? | ||
!!@move_home | ||
end | ||
|
||
# @return [Boolean] | ||
def adapt_home_ownership? | ||
!!@adapt_home_ownership | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright (c) [2021] SUSE LLC | ||
# | ||
# All Rights Reserved. | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of version 2 of the GNU General Public License as published | ||
# by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
# more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, contact SUSE LLC. | ||
# | ||
# To contact SUSE LLC about this file by physical or electronic mail, you may | ||
# find current contact information at www.suse.com. | ||
|
||
require "y2users/collection" | ||
|
||
module Y2Users | ||
# Collection of commit configs | ||
# | ||
# @see CommitConfig | ||
class CommitConfigCollection < Collection | ||
# Constructor | ||
# | ||
# @param commit_configs [Array<CommitConfig>] | ||
def initialize(commit_configs = []) | ||
super | ||
end | ||
|
||
# Commit config for the given user | ||
# | ||
# @param value [String] username | ||
# @return [CommitConfig, nil] nil if the collection does not include a commit config for the | ||
# given username | ||
def by_username(value) | ||
find { |c| c.username == value } | ||
end | ||
end | ||
end |
Oops, something went wrong.