Gossamer Forum
Home : Products : DBMan : Customization :

Multipe Owners of a Record

Quote Reply
Multipe Owners of a Record
I need to develop a mechanism for specifying multiple owners of a record. I records to be viewed and modified by their owners. However, each record will have a minimum of two owners who should both be able to view/modify the record.

Any ideas how to set this up?

I have thought about changing $auth_user_field to an array. However, I haven't figured out how to support a field which is an array instead of a string.

I wanted to post this before I start working too hard on a fix to see if the great dbman community had more brilliant ideas for this function.

Sincerely,
Lauren
Quote Reply
Re: Multipe Owners of a Record In reply to
I'd really like to see your ideas on this as you go along, Lauren. This is a wrinkle I've never thought of before.

(BTW, I promised you I'd have something for you by Tuesday. It's Thursday. It isn't done. Smile )



------------------
JPD





Quote Reply
Re: Multipe Owners of a Record In reply to
I'll post my own solution!

If a record has more than one owner simply make the userid field contain more than one userid separated by spaces. For example if joe and tom should be able to view record 1, then for record1, $rec{'userid'} = 'joe tom'.

Make sure that $auth_user_field in .cfg points to the field # for 'userid' and that
$auth_modify_own and $auth_view_own both are 1.

Make the following changes in db.cgi:

1) in sub query, add $auth to the first my statement, then replace:

####################
Code:
# Now we go through the database and do the actual searching.
# First figure out which records we want:
$first = ($maxhits * ($nh - 1));
$last = $first + $maxhits - 1;

open (DB, "<$db_file_name") or &cgierr("error in search. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
(/^#/) and next LINE; # Skip comment Lines.
(/^\s*$/) and next LINE; # Skip blank lines.
$line = $_; chomp ($line); # Remove trailing new line.
@values = &split_decode($line);

# If we are only allowed to view/mod our own record, then let's check here.
next LINE if ($restricted and ($db_userid ne $values[$auth_user_field]));
####################

with

####################
Code:
# Now we go through the database and do the actual searching.
# First figure out which records we want:
$first = ($maxhits * ($nh - 1));
$last = $first + $maxhits - 1;

open (DB, "<$db_file_name") or &cgierr("error in search. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
(/^#/) and next LINE; # Skip comment Lines.
(/^\s*$/) and next LINE; # Skip blank lines.
$line = $_; chomp ($line); # Remove trailing new line.
@values = &split_decode($line);
@auth_users = split(' ',"$values[$auth_user_field]");

# If we are only allowed to view/mod our own record, then let's check here.
if ($restricted) {
$auth = 0;
foreach $user (@auth_users) {
if ($db_userid eq $user) { $auth++; }
}
next LINE if ($auth == 0);
}
####################

2) Corresponding changes need to be made in sub get_record, sub delete_record, and sub modify_record. Note that in some of these subroutines the @values does not exist. In these routines it is called @data.

If anyone wants more details feel free to ask.

Lauren
Quote Reply
Re: Multipe Owners of a Record In reply to
Excellent!


------------------
JPD