I want to allow users to share documents in a database-drive application (a few different things, actually).
I have designed the following schema to allow for this (postgresql).
Here we go...questions at the bottom.
Diagram (minus lookup tables):

A lookup table for party types:
create table partyType(
id int not null primary key,
description text not null
);
insert into partyType values (1, 'Individual');
insert into partyType values (2, 'Organization');
A party is an individual or organization, such as a user or customer:
create table party(
id serial primary key,
type int not null,
name text not null,
foreign key (type) references partyType (id)
);
A party has many email addresses, and an email address can belong to multiple parties (such as "barb and jim jones"):
create table emailAddress(
id serial primary key,
address text not null
);
create table partyEmailAddress(
partyId int not null,
emailAddressId int not null,
primary key (partyId, emailAddressId),
foreign key (partyId) references party (id),
foreign key (emailAddressId) references emailAddress (id)
);
An item can be private or explicitly shared, or public but unlisted, or public and listed:
create table visibilityType(
id int not null primary key,
description text not null
);
insert into visibilityType values (1, 'Private / Explicit');
insert into visibilityType values (2, 'Public Unlisted');
insert into visibilityType values (3, 'Public Listed');
Someone with whom you share an item can be a viewer, commenter (can view too), or editor:
create table sharingRoleType(
id int not null primary key,
description text not null
);
insert into sharingRoleType values (1, 'Viewer');
insert into sharingRoleType values (2, 'Commenter');
insert into sharingRoleType values (3, 'Editor');
An item is the thing that you are sharing (this will be an actual type like Document later):
create table item(
id serial primary key,
ownerId int not null,
visibilityType int not null default 1,
publicRoleType int not null default 1 comment 'the role, if the item is public',
onlyOwnerCanChangePermissions boolean not null default true,
foreign key (ownerId) references party (id),
foreign key (visibilityType) references visibilityType (id)
foreign key (publicRoleType) references sharingRoleType (id)
);
Got a more succinct name than "onlyOwnerCanChangePermissions" ? In gdocs, either only the owner can change permissions, or you can allow other editors to change permissions and add other users.
The below allows an item to be shared with many, and for a party (via their email) to have many items shared with it.
create table itemShare(
itemId int not null,
emailAddressId int not null,
roleType int not null default 1,
primary key (itemId, emailAddressId),
foreign key (itemId) references item (id),
foreign key (emailAddressId) references emailAddress (id),
foreign key (roleType) references sharingRoleType (id)
);
Should item.ownerId be removed from item and added as a role type, and be added as an "automatic" itemShare ? Would be easier to query for all docs that a user has access to this way.
Is item.publicRoleType correct, seeing as it's only used if the item is public? Seems somewhat denormalized...could move visibilityType to itemShare, and get rid of publicRoleType, make email addy nullable on itemShare