Skip to content

Commit

Permalink
Add missing files for system config functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
abeverley committed Oct 7, 2024
1 parent 78d6b47 commit 44efec6
Show file tree
Hide file tree
Showing 30 changed files with 5,217 additions and 0 deletions.
72 changes: 72 additions & 0 deletions lib/Brass/DBIC.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
=pod
Brass
Copyright (C) 2024 Ctrl O Ltd
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
=cut

package Brass::DBIC;

use base qw(DBIx::Class);

# Used as a component for result sources to perform additional DBIC functions
# (such as validation of values). For validation, the Result needs a
# validate() function. It should raise an exception if there is a problem.

sub insert
{ my $self = shift;
$self->_validate(@_);
$self->_before_create(@_);
my $guard = $self->result_source->schema->txn_scope_guard;
my $return = $self->next::method(@_);
$self->after_create
if $self->can('after_create');
$guard->commit;
$return;
}

sub delete
{ my $self = shift;
$self->before_delete
if $self->can('before_delete');
$self->next::method(@_);
}

sub update
{ my $self = shift;
$self->_validate(@_);
$self->next::method(@_);
}

sub _validate
{ my ($self, $values) = @_;
# If update() has been called with a set of values, then these need to be
# updated in the object first, otherwise validation will be done on the
# existing values in the object not the new ones.
if ($values)
{
$self->$_($values->{$_}) foreach keys %$values;
}
$self->validate
if $self->can('validate');
};

sub _before_create
{ my $self = shift;
$self->before_create
if $self->can('before_create');
};


1;
37 changes: 37 additions & 0 deletions lib/Brass/Schema/Result/Config.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use utf8;
package Brass::Schema::Result::Config;

use strict;
use warnings;

use Log::Report;
use Net::CIDR;

use base 'DBIx::Class::Core';

__PACKAGE__->load_components("+Brass::DBIC");

__PACKAGE__->table("config");

__PACKAGE__->add_columns(
"id",
{ data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
"internal_networks",
{ data_type => "text", is_nullable => 1 },
"smtp_relayhost",
{ data_type => "text", is_nullable => 1 },
);

__PACKAGE__->set_primary_key("id");

sub validate
{ my $self = shift;

foreach my $range (split /[\s,]+/, $self->internal_networks)
{
Net::CIDR::cidrvalidate($range)
or error __x"Invalid IP range restriction: {range}", range => $range;
}
}

1;
185 changes: 185 additions & 0 deletions share/fixtures/43/conf/all_tables.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"belongs_to" : {
"fetch" : 0
},
"sets" : [
{
"quantity" : "all",
"class" : "Config"
},
{
"quantity" : "all",
"class" : "ServerServertype"
},
{
"class" : "IssueTag",
"quantity" : "all"
},
{
"quantity" : "all",
"class" : "CertLocationUse"
},
{
"quantity" : "all",
"class" : "Domain"
},
{
"quantity" : "all",
"class" : "Docsend"
},
{
"class" : "App",
"quantity" : "all"
},
{
"class" : "Docreadtype",
"quantity" : "all"
},
{
"quantity" : "all",
"class" : "DocDocreadtype"
},
{
"quantity" : "all",
"class" : "File"
},
{
"class" : "Customer",
"quantity" : "all"
},
{
"class" : "User",
"quantity" : "all"
},
{
"class" : "Tag",
"quantity" : "all"
},
{
"quantity" : "all",
"class" : "UserDocread"
},
{
"class" : "Uad",
"quantity" : "all"
},
{
"quantity" : "all",
"class" : "ServerPw"
},
{
"class" : "Project",
"quantity" : "all"
},
{
"quantity" : "all",
"class" : "Cert"
},
{
"quantity" : "all",
"class" : "UserTopic"
},
{
"class" : "EventPerson",
"quantity" : "all"
},
{
"class" : "Permission",
"quantity" : "all"
},
{
"class" : "Comment",
"quantity" : "all"
},
{
"quantity" : "all",
"class" : "CertUse"
},
{
"quantity" : "all",
"class" : "Servertype"
},
{
"class" : "UserProject",
"quantity" : "all"
},
{
"class" : "ServerCert",
"quantity" : "all"
},
{
"class" : "Pw",
"quantity" : "all"
},
{
"class" : "Event",
"quantity" : "all"
},
{
"quantity" : "all",
"class" : "PwServertype"
},
{
"quantity" : "all",
"class" : "Site"
},
{
"class" : "Issuetype",
"quantity" : "all"
},
{
"class" : "IssuePriority",
"quantity" : "all"
},
{
"class" : "Status",
"quantity" : "all"
},
{
"class" : "Calendar",
"quantity" : "all"
},
{
"quantity" : "all",
"class" : "Server"
},
{
"quantity" : "all",
"class" : "IssueStatus"
},
{
"class" : "Eventtype",
"quantity" : "all"
},
{
"quantity" : "all",
"class" : "Issue"
},
{
"quantity" : "all",
"class" : "UserDocreadtype"
},
{
"class" : "Priority",
"quantity" : "all"
},
{
"class" : "CertLocation",
"quantity" : "all"
},
{
"class" : "UserPermission",
"quantity" : "all"
},
{
"class" : "UserServertype",
"quantity" : "all"
}
],
"has_many" : {
"fetch" : 0
},
"might_have" : {
"fetch" : 0
}
}
17 changes: 17 additions & 0 deletions share/fixtures/43/conf/permission.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"has_many" : {
"fetch" : 0
},
"sets" : [
{
"quantity" : "all",
"class" : "Permission"
}
],
"might_have" : {
"fetch" : 0
},
"belongs_to" : {
"fetch" : 0
}
}
17 changes: 17 additions & 0 deletions share/fixtures/43/permission/_config_set
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
$VAR1 = {
'belongs_to' => {
'fetch' => 0
},
'has_many' => {
'fetch' => 0
},
'might_have' => {
'fetch' => 0
},
'sets' => [
{
'quantity' => 'all',
'class' => 'Permission'
}
]
};
1 change: 1 addition & 0 deletions share/fixtures/43/permission/_dumper_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.001039
6 changes: 6 additions & 0 deletions share/fixtures/43/permission/permission/1.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$HASH1 = {
description
=> 'User can view documents',
id => 1,
name => 'doc'
};
6 changes: 6 additions & 0 deletions share/fixtures/43/permission/permission/10.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$HASH1 = {
description
=> 'User can view configuration information',
id => 10,
name => 'config'
};
6 changes: 6 additions & 0 deletions share/fixtures/43/permission/permission/11.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$HASH1 = {
description
=> 'User can write configuration information',
id => 11,
name => 'config_write'
};
6 changes: 6 additions & 0 deletions share/fixtures/43/permission/permission/12.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$HASH1 = {
description
=> 'User can create and update any issue for certain projects',
id => 12,
name => 'issue_write_project'
};
6 changes: 6 additions & 0 deletions share/fixtures/43/permission/permission/13.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$HASH1 = {
description
=> 'User can read the calendar',
id => 13,
name => 'calendar_read'
};
6 changes: 6 additions & 0 deletions share/fixtures/43/permission/permission/14.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$HASH1 = {
description
=> 'User can write to the calendar',
id => 14,
name => 'calendar_write'
};
6 changes: 6 additions & 0 deletions share/fixtures/43/permission/permission/15.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$HASH1 = {
description
=> 'User administrator',
id => 15,
name => 'user_admin'
};
6 changes: 6 additions & 0 deletions share/fixtures/43/permission/permission/16.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$HASH1 = {
description
=> 'User receives brass reports',
id => 16,
name => 'reports'
};
6 changes: 6 additions & 0 deletions share/fixtures/43/permission/permission/17.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$HASH1 = {
description
=> 'User receives notification of all new issues',
id => 17,
name => 'new_issue_alert'
};
Loading

0 comments on commit 44efec6

Please sign in to comment.