Skip to content

Commit

Permalink
feat(client): add group owners edition
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Dec 9, 2016
1 parent 321e951 commit 2021a36
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
12 changes: 7 additions & 5 deletions src/client/actions/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ function updateGroup(groupName, type, value, method) {
throw new Error('wrong method');
}
const groupUrl = `db/${dbManager.currentDb}/group/${groupName}`;
if (type === 'users') {
const url = `${groupUrl}/user/${value}`;
return updateGroupAction(apiFetchJSON(url, {method}).then(() => apiFetchJSON(groupUrl)));
let url;
if (type === 'owners') {
url = `${groupUrl}/_owner/${value}`;
} else if (type === 'users') {
url = `${groupUrl}/user/${value}`;
} else if (type === 'rights') {
const url = `${groupUrl}/right/${value}`;
return updateGroupAction(apiFetchJSON(url, {method}).then(() => apiFetchJSON(groupUrl)));
url = `${groupUrl}/right/${value}`;
} else {
throw new Error('unreachable');
}
return updateGroupAction(apiFetchJSON(url, {method}).then(() => apiFetchJSON(groupUrl)));
}

export const CREATE_GROUP = 'CREATE_GROUP';
Expand Down
2 changes: 1 addition & 1 deletion src/client/components/GroupDataEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const GroupDataEditor = ({type, data, addValue, removeValue}) => (
</tr>
</thead>
<tbody>
{data.map((value) => (<GroupDataElement key={value} value={value} removeValue={removeValue} />))}
{data.map((value, i) => (<GroupDataElement key={value} value={value} removeValue={removeValue} editable={i !== 0} />))}
<tr>
<td>
<EnterTextField onSubmit={addValue} />
Expand Down
13 changes: 9 additions & 4 deletions src/client/components/GroupDataElement.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import React from 'react';

const GroupDataElement = ({value, removeValue}) => (
const GroupDataElement = ({value, removeValue, editable}) => (
<tr>
<td>
{value}
</td>
<td className="td-action">
<button type="button" className="btn btn-danger btn-simple btn-xs" onClick={() => removeValue(value)}>
<i className="fa fa-times" />
</button>
{
editable ?
<button type="button" className="btn btn-danger btn-simple btn-xs" onClick={() => removeValue(value)}>
<i className="fa fa-times" />
</button> :
null
}

</td>
</tr>
);
Expand Down
13 changes: 11 additions & 2 deletions src/client/components/GroupEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,24 @@ const GroupEditor = ({group, addValueToGroup, removeValueFromGroup, removeGroup}
<div className="content">
<div className="container-fluid">
<div className="row">
<div className="col-md-6">
<div className="col-md-4">
<GroupDataEditor
type="owners"
owners={true}
data={group.$owners}
addValue={(value) => addValueToGroup(group.name, 'owners', value)}
removeValue={(value) => removeValueFromGroup(group.name, 'owners', value)}
/>
</div>
<div className="col-md-4">
<GroupDataEditor
type="users"
data={group.users}
addValue={(value) => addValueToGroup(group.name, 'users', value)}
removeValue={(value) => removeValueFromGroup(group.name, 'users', value)}
/>
</div>
<div className="col-md-6">
<div className="col-md-4">
<GroupDataEditor
type="rights"
data={group.rights}
Expand Down
4 changes: 2 additions & 2 deletions src/couch/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const methods = {
},

async addOwnersToDoc(uuid, user, owners, type, options) {
debug.trace('addOwnersToDoc');
debug(`addOwnersToDoc (${uuid}, ${user})`);
await this.open();
owners = util.ensureOwnersArray(owners);
const doc = await this.getDocByRights(uuid, user, 'owner', type, options);
Expand All @@ -47,7 +47,7 @@ const methods = {
},

async removeOwnersFromDoc(uuid, user, owners, type, options) {
debug.trace('removeOwnersFromDoc');
debug.trace(`removeOwnersFromDoc (${uuid}, ${user})`);
await this.open();
owners = util.ensureOwnersArray(owners);
const doc = await this.getDocByRights(uuid, user, 'owner', type, options);
Expand Down

0 comments on commit 2021a36

Please sign in to comment.