summaryrefslogtreecommitdiff
path: root/usr
diff options
context:
space:
mode:
authorJulian Blake Kongslie <jblake@omgwallhack.org>2010-03-18 13:06:24 -0700
committerJulian Blake Kongslie <jblake@omgwallhack.org>2010-03-18 13:06:24 -0700
commit0df6b8d376c6cbac0ed3df910cdcc10c06bd3e18 (patch)
treeb868e49eaba3592a9a26fd51aaa11c78ea127cb9 /usr
parent46f08c97433ed083bb479b00637c6aa5cb7b24d3 (diff)
downloadpiny-code-0df6b8d376c6cbac0ed3df910cdcc10c06bd3e18.tar.gz
piny-code-0df6b8d376c6cbac0ed3df910cdcc10c06bd3e18.zip
Add methods for managing group membership, and some more constraints.
Diffstat (limited to 'usr')
-rw-r--r--usr/src/libpiny/lib/Piny/Group.pm24
-rw-r--r--usr/src/libpiny/lib/Piny/Repo.pm47
-rw-r--r--usr/src/libpiny/lib/Piny/User.pm29
3 files changed, 97 insertions, 3 deletions
diff --git a/usr/src/libpiny/lib/Piny/Group.pm b/usr/src/libpiny/lib/Piny/Group.pm
index 4b957a7..c1df42d 100644
--- a/usr/src/libpiny/lib/Piny/Group.pm
+++ b/usr/src/libpiny/lib/Piny/Group.pm
@@ -35,6 +35,30 @@ has 'members' =>
, init_arg => undef
);
+# Public methods
+
+sub add_member {
+ my ( $s, @users ) = @_;
+
+ foreach my $user ( @users ) {
+ system( "adduser", $user->username( ), $s->groupname( ) );
+ $user->clear_groups( );
+ };
+
+ $s->clear_members( );
+};
+
+sub remove_member {
+ my ( $s, @users ) = @_;
+
+ foreach my $user ( @users ) {
+ system( "deluser", $user->username( ), $s->groupname( ) );
+ $user->clear_groups( );
+ };
+
+ $s->clear_members( );
+};
+
# Builder methods
# If constructed with just one argument, then
diff --git a/usr/src/libpiny/lib/Piny/Repo.pm b/usr/src/libpiny/lib/Piny/Repo.pm
index 4783960..6dcabca 100644
--- a/usr/src/libpiny/lib/Piny/Repo.pm
+++ b/usr/src/libpiny/lib/Piny/Repo.pm
@@ -4,20 +4,43 @@
package Piny::Repo;
use Moose;
+use Moose::Util::TypeConstraints;
use File::Find qw( find );
+use Piny::Group;
use Piny::User;
+# Types
+
+subtype 'Reponame'
+ => as 'Str'
+ => where { $_ =~ /^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/ }
+ => message { 'That name is not in the correct format for a piny repo.' }
+ ;
+
+subtype 'SimpleText'
+ => as 'Str'
+ => where { $_ =~ /^[\x{0020}-\x{FDCF}\x{FDF0}-\x{FFFD}]{1,80}$/ }
+ => message { 'That description is not in the correct format for a piny repo.' }
+ ;
+
# Attributes
has 'name' =>
( is => 'rw'
- , isa => 'Str'
+ , isa => 'Reponame'
, trigger => \&_rename_repo
, required => 1
);
+has 'group' =>
+ ( is => 'ro'
+ , isa => 'Piny::Group'
+ , lazy_build => 1
+ , init_arg => undef
+ );
+
has 'path' =>
( is => 'ro'
, isa => 'Str'
@@ -27,7 +50,7 @@ has 'path' =>
has 'description' =>
( is => 'rw'
- , isa => 'Str'
+ , isa => 'SimpleText'
, trigger => \&_set_description
, lazy_build => 1
, init_arg => undef
@@ -62,6 +85,20 @@ has 'globally_writable' =>
, init_arg => undef
);
+# Public methods
+
+sub add_access {
+ my ( $s, @users ) = @_;
+
+ $s->group( )->add_member( @users );
+};
+
+sub remove_access {
+ my ( $s, @users ) = @_;
+
+ $s->group( )->remove_member( @users );
+};
+
# Triggers
sub _rename_repo {
@@ -108,6 +145,12 @@ around BUILDARGS => sub {
};
};
+sub _build_group {
+ my ( $s ) = @_;
+
+ return Piny::Group->new( groupname => "git-" . $s->name( ) );
+};
+
sub _build_path {
my ( $s ) = @_;
diff --git a/usr/src/libpiny/lib/Piny/User.pm b/usr/src/libpiny/lib/Piny/User.pm
index 53e310b..e4b865c 100644
--- a/usr/src/libpiny/lib/Piny/User.pm
+++ b/usr/src/libpiny/lib/Piny/User.pm
@@ -4,10 +4,19 @@
package Piny::User;
use Moose;
+use Moose::Util::TypeConstraints;
use Piny::Email;
use Piny::Group;
+# Types
+
+subtype 'Username'
+ => as 'Str'
+ => where { $_ =~ /^(?!(git|ikiwiki)-)[[a-zA-Z0-9][a-zA-Z0-9_.-]*$/ }
+ => message { 'That username is not in the correct format for a piny user.' }
+ ;
+
# Attributes
has 'uid' =>
@@ -18,7 +27,7 @@ has 'uid' =>
has 'username' =>
( is => 'ro'
- , isa => 'Str'
+ , isa => 'Username'
, lazy_build => 1
);
@@ -50,6 +59,24 @@ has 'groups' =>
, init_arg => undef
);
+# Public methods
+
+sub add_group {
+ my ( $s, @groups ) = @_;
+
+ foreach my $group ( @groups ) {
+ $group->add_member( $s );
+ };
+};
+
+sub remove_group {
+ my ( $s, @groups ) = @_;
+
+ foreach my $group ( @groups ) {
+ $group->remove_member( $s );
+ };
+};
+
# Builder methods
# If constructed with just one argument, then