diff options
author | ivan <ivan> | 2006-06-18 12:54:49 +0000 |
---|---|---|
committer | ivan <ivan> | 2006-06-18 12:54:49 +0000 |
commit | c738a3c4923774b64960aa87fa58bd0751487edb (patch) | |
tree | e037c5c2e1211dd16c8024f16c9ce4d1fe589efb /httemplate | |
parent | aaad08cae3a0d46d012de5b78360101cda836c30 (diff) |
ACLs: finish group edit (agents + rights) & browse
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/browse/access_group.html | 45 | ||||
-rw-r--r-- | httemplate/browse/access_user.html | 2 | ||||
-rw-r--r-- | httemplate/edit/access_group.html | 36 | ||||
-rw-r--r-- | httemplate/edit/elements/edit.html | 21 | ||||
-rwxr-xr-x | httemplate/edit/part_pkg.cgi | 2 | ||||
-rw-r--r-- | httemplate/edit/process/access_group.html | 10 | ||||
-rw-r--r-- | httemplate/edit/process/elements/process.html | 15 | ||||
-rw-r--r-- | httemplate/elements/checkboxes-table-name.html | 85 | ||||
-rw-r--r-- | httemplate/elements/checkboxes-table.html | 28 |
9 files changed, 233 insertions, 11 deletions
diff --git a/httemplate/browse/access_group.html b/httemplate/browse/access_group.html index 6ba89ea81..9ebb2b882 100644 --- a/httemplate/browse/access_group.html +++ b/httemplate/browse/access_group.html @@ -4,6 +4,45 @@ my $html_init = "Internal access groups control access to the back-office interface.<BR><BR>". qq!<A HREF="${p}edit/access_group.html"><I>Add an internal access group</I></A><BR><BR>!; +#false laziness w/access_user.html & agent_type.cgi +my $agents_sub = sub { + my $access_group = shift; + + [ map { + my $access_groupagent = $_; + my $agent = $access_groupagent->agent; + [ + { + 'data' => $agent->agent, + 'align' => 'left', + 'link' => $p. 'edit/agent.cgi?'. $agent->agentnum, + }, + ]; + } + grep { $_->agent } #? + $access_group->access_groupagent, + + ]; + +}; + +my $rights_sub = sub { + my $access_group = shift; + + [ map { my $access_right = $_; + [ + { + 'data' => $access_right->rightname, + 'align' => 'left', + }, + ]; + } + $access_group->access_rights, + + ]; + +}; + my $count_query = 'SELECT COUNT(*) FROM access_group'; my $link = [ $p.'edit/access_group.html?', 'groupnum' ]; @@ -22,12 +61,18 @@ my $link = [ $p.'edit/access_group.html?', 'groupnum' ]; 'count_query' => $count_query, 'header' => [ '#', 'Group name', + 'Agents', + 'Rights', ], 'fields' => [ 'groupnum', 'groupname', + $agents_sub, + $rights_sub, ], 'links' => [ $link, $link, + '', + '', ], ) %> diff --git a/httemplate/browse/access_user.html b/httemplate/browse/access_user.html index 38d5430b1..be11bf82a 100644 --- a/httemplate/browse/access_user.html +++ b/httemplate/browse/access_user.html @@ -4,7 +4,7 @@ my $html_init = "Internal users have access to the back-office interface. Typically, this is your employees and contractors, but in a VISP setup, you can also add accounts for your reseller's employees. It is <B>highly recommended</B> to add a <B>separate account for each person</B> rather than using role accounts.<BR><BR>". qq!<A HREF="${p}edit/access_user.html"><I>Add an internal user</I></A><BR><BR>!; -#false laziness w/agent_type.cgi +#false laziness w/access_group.html & agent_type.cgi my $groups_sub = sub { my $access_user = shift; diff --git a/httemplate/edit/access_group.html b/httemplate/edit/access_group.html index 11b8df7bc..d7f7667f4 100644 --- a/httemplate/edit/access_group.html +++ b/httemplate/edit/access_group.html @@ -5,6 +5,42 @@ 'groupnum' => 'Group number', 'groupname' => 'Group name', }, + 'viewall_dir' => 'browse', + + 'html_bottom' => + sub { + my $access_group = shift; + + "<BR>Group virtualized to customers of agents:<BR>". + ntable("#cccccc",2). + '<TR><TD>'. + include( '/elements/checkboxes-table.html', + 'source_obj' => $access_group, + 'link_table' => 'access_groupagent', + 'target_table' => 'agent', + 'name_col' => 'agent', + 'target_link' => $p.'edit/agent.cgi?', + 'disable-able' => 1, + ). + '</TR></TD></TABLE>'. + + "<BR>Group rights:<BR>". + ntable("#cccccc",2). + '<TR><TD>'. + include( '/elements/checkboxes-table-name.html', + 'source_obj' => $access_group, + 'link_table' => 'access_right', + 'link_static' => { 'righttype' => + 'FS::access_group', + }, + 'num_col' => 'rightobjnum', + 'name_col' => 'rightname', + 'names_list' => [ FS::AccessRight->rights() ], + ). + '</TR></TD></TABLE>' + + ; + }, ) %> diff --git a/httemplate/edit/elements/edit.html b/httemplate/edit/elements/edit.html index 120c03a3c..94bf6eecd 100644 --- a/httemplate/edit/elements/edit.html +++ b/httemplate/edit/elements/edit.html @@ -16,6 +16,18 @@ # # 'menubar' => '', #menubar arrayref # + # #run when re-displaying with an error + # 'error_callback' => sub { my $cgi, $object = @_; }, + # + # #run when editing + # 'edit_callback' => sub { my $cgi, $object = @_; }, + # + # #run when adding + # 'new_callback' => sub { my $cgi, $object = @_; }, + # + # #broken'html_table_bottom' => '', #string or listref of additinal HTML to + # #add before </TABLE> + # # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search' # # 'html_bottom' => '', #string @@ -43,16 +55,25 @@ map { $_ => scalar($cgi->param($_)) } fields($table) }); + &{$opt{'error_callback'}}($cgi, $object) + if $opt{'error_callback'}; + } elsif ( $cgi->keywords ) { #editing my( $query ) = $cgi->keywords; $query =~ /^(\d+)$/; $object = qsearchs( $table, { $pkey => $1 } ); + &{$opt{'edit_callback'}}($cgi, $object) + if $opt{'edit_callback'}; + } else { #adding $object = $class->new( {} ); + &{$opt{'new_callback'}}($cgi, $object) + if $opt{'new_callback'}; + } my $action = $object->$pkey() ? 'Edit' : 'Add'; diff --git a/httemplate/edit/part_pkg.cgi b/httemplate/edit/part_pkg.cgi index 462d5161f..b085d2260 100755 --- a/httemplate/edit/part_pkg.cgi +++ b/httemplate/edit/part_pkg.cgi @@ -237,7 +237,7 @@ if ( dbdef->table('pkg_svc')->column('primary_svc') ) { push @form_radio, 'pkg_svc_primary'; } -tie my %freq, 'Tie::IxHash', %FS::part_pkg::freq; +tie my %freq, 'Tie::IxHash', %{FS::part_pkg->freqs_href()}; if ( $part_pkg->dbdef_table->column('freq')->type =~ /(int)/i ) { delete $freq{$_} foreach grep { ! /^\d+$/ } keys %freq; } diff --git a/httemplate/edit/process/access_group.html b/httemplate/edit/process/access_group.html index e8c6d07b1..9bb9d1dda 100644 --- a/httemplate/edit/process/access_group.html +++ b/httemplate/edit/process/access_group.html @@ -1,5 +1,15 @@ <%= include( 'elements/process.html', 'table' => 'access_group', 'viewall_dir' => 'browse', + 'process_m2m' => { 'link_table' => 'access_groupagent', + 'target_table' => 'agent', + }, + 'process_m2name' => { + 'link_table' => 'access_right', + 'link_static' => { 'righttype' => 'FS::access_group', }, + 'num_col' => 'rightobjnum', + 'name_col' => 'rightname', + 'names_list' => [ FS::AccessRight->rights() ], + }, ) %> diff --git a/httemplate/edit/process/elements/process.html b/httemplate/edit/process/elements/process.html index 59ad35ee4..a6e3b50e3 100644 --- a/httemplate/edit/process/elements/process.html +++ b/httemplate/edit/process/elements/process.html @@ -16,7 +16,14 @@ # 'viewall_dir' => '', #'search' or 'browse', defaults to 'search' # 'process_m2m' => { 'link_table' => 'link_table_name', # 'target_table' => 'target_table_name', - # }. + # }, + # 'process_m2name' => { 'link_table' => 'link_table_name', + # 'link_static' => { 'column' => 'value' }, + # 'num_col' => 'column', #if column name is different in + # #link_table than source_table + # 'name_col' => 'name_column', + # 'names_list' => [ 'list', 'names' ], + # }, my(%opt) = @_; @@ -52,6 +59,12 @@ ); } + if ( !$error && $opt{'process_m2name'} ) { + $error = $new->process_m2name( %{ $opt{'process_m2name'} }, + 'params' => scalar($cgi->Vars), + ); + } + if ( $error ) { $cgi->param('error', $error); print $cgi->redirect(popurl(2). "$table.html?". $cgi->query_string ); diff --git a/httemplate/elements/checkboxes-table-name.html b/httemplate/elements/checkboxes-table-name.html new file mode 100644 index 000000000..8e9dd29d2 --- /dev/null +++ b/httemplate/elements/checkboxes-table-name.html @@ -0,0 +1,85 @@ +<% + + ## + # required + ## + # 'link_table' => 'table_name', + # + # 'name_col' => 'name_column', + # #or + # 'name_callback' => sub { }, + # + # 'names_list' => [ 'value', 'other value' ], + # + ## + # recommended (required?) + ## + # 'source_obj' => $obj, + # #or? + # #'source_table' => 'table_name', + # #'sourcenum' => '4', #current value of primary key in source_table + # # # (none is okay, just pass it if you have it) + ## + # optional + ## + # 'num_col' => 'col_name' #if column name is different in link_table than + # #source_table + # 'link_static' => { 'column' => 'value' }, + + my( %opt ) = @_; + + my( $source_pkey, $sourcenum, $source_obj ); + if ( $opt{'source_obj'} ) { + + $source_obj = $opt{'source_obj'}; + #$source_table = $source_obj->dbdef_table->table; + $source_pkey = $source_obj->dbdef_table->primary_key; + $sourcenum = $source_obj->$source_pkey(); + + } else { + + #$source_obj? + $source_pkey = $opt{'source_table'} + ? dbdef->table($opt{'source_table'})->primary_key + : ''; + $sourcenum = $opt{'sourcenum'}; + } + + $source_pkey = $opt{'num_col'} || $source_pkey; + + my $link_static = $opt{'link_static'} || {}; + +%> + +<% foreach my $name ( @{ $opt{'names_list'} } ) { + + my $checked; + if ( $cgi->param('error') ) { + + $checked = $cgi->param($opt{'link_table'}. ".$name" ) + ? 'CHECKED' + : ''; + + } else { + + $checked = + qsearchs( $opt{'link_table'}, { + $source_pkey => $sourcenum, + $opt{'name_col'} => $name, + %$link_static, + } ) + ? 'CHECKED' + : '' + + } + +%> + + <INPUT TYPE="checkbox" NAME="<%= $opt{'link_table'}. ".$name" %>" <%= $checked %> VALUE="ON"> + + <%= $name %> + + <BR> + +<% } %> + diff --git a/httemplate/elements/checkboxes-table.html b/httemplate/elements/checkboxes-table.html index d26ebef35..16376fa3d 100644 --- a/httemplate/elements/checkboxes-table.html +++ b/httemplate/elements/checkboxes-table.html @@ -68,16 +68,28 @@ ) { my $targetnum = $target_obj->$target_pkey(); + + my $checked; + if ( $cgi->param('error') ) { + + $checked = $cgi->param($target_pkey.$targetnum) + ? 'CHECKED' + : ''; + + } else { + + $checked = qsearchs( $opt{'link_table'}, { + $source_pkey => $sourcenum, + $target_pkey => $targetnum, + } ) + ? 'CHECKED' + : '' + + } + %> - <INPUT TYPE="checkbox" NAME="<%= $target_pkey. $targetnum %>" <%= - qsearchs( $opt{'link_table'}, { - $source_pkey => $sourcenum, - $target_pkey => $targetnum, - }) - ? 'CHECKED ' - : '' - %> VALUE="ON"> + <INPUT TYPE="checkbox" NAME="<%= $target_pkey. $targetnum %>" <%= $checked %> VALUE="ON"> <% if ( $opt{'target_link'} ) { %> |