Implement super basic user sharing for budgets
Signed-off-by: William Brawner <me@wbrawner.com>
This commit is contained in:
parent
3c4a5bd321
commit
e4a3855d83
4 changed files with 258 additions and 211 deletions
|
@ -88,15 +88,23 @@ class BudgetController extends Controller
|
||||||
$budget->setDescription($description);
|
$budget->setDescription($description);
|
||||||
$budget = $this->budgetMapper->insert($budget);
|
$budget = $this->budgetMapper->insert($budget);
|
||||||
$userPermissions = [];
|
$userPermissions = [];
|
||||||
$users[$this->userId] = UserPermission::PERMISSION_MANAGE;
|
|
||||||
foreach ($users as $user => $permission) {
|
foreach ($users as $user) {
|
||||||
|
if ($user['user'] === $this->userId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$userPermission = new UserPermission();
|
$userPermission = new UserPermission();
|
||||||
$userPermission->setBudgetId($budget->getId());
|
$userPermission->setBudgetId($budget->getId());
|
||||||
$userPermission->setUserId($user);
|
$userPermission->setUserId($user['user']);
|
||||||
$userPermission->setPermission($permission);
|
$userPermission->setPermission($user['permission']);
|
||||||
$userPermission = $this->userPermissionMapper->insert($userPermission);
|
$userPermission = $this->userPermissionMapper->insert($userPermission);
|
||||||
array_push($userPermissions, $userPermission);
|
array_push($userPermissions, $userPermission);
|
||||||
}
|
}
|
||||||
|
$userPermission = new UserPermission();
|
||||||
|
$userPermission->setBudgetId($budget->getId());
|
||||||
|
$userPermission->setUserId($this->userId);
|
||||||
|
$userPermission->setPermission(UserPermission::PERMISSION_MANAGE);
|
||||||
|
array_push($userPermissions, $this->userPermissionMapper->insert($userPermission));
|
||||||
$budget->setUsers($userPermissions);
|
$budget->setUsers($userPermissions);
|
||||||
return new DataResponse($budget);
|
return new DataResponse($budget);
|
||||||
}
|
}
|
||||||
|
@ -121,31 +129,31 @@ class BudgetController extends Controller
|
||||||
if ($userPermission->getPermission() != UserPermission::PERMISSION_MANAGE) {
|
if ($userPermission->getPermission() != UserPermission::PERMISSION_MANAGE) {
|
||||||
return new DataResponse([], Http::STATUS_FORBIDDEN);
|
return new DataResponse([], Http::STATUS_FORBIDDEN);
|
||||||
}
|
}
|
||||||
if ($name) {
|
|
||||||
$budget->setName($name);
|
$budget->setName($name);
|
||||||
}
|
|
||||||
if ($description) {
|
|
||||||
$budget->setDescription($description);
|
$budget->setDescription($description);
|
||||||
}
|
|
||||||
$budget = $this->budgetMapper->update($budget);
|
$budget = $this->budgetMapper->update($budget);
|
||||||
if ($users) {
|
if ($users) {
|
||||||
$this->userPermissionMapper->deleteAll($budget->id);
|
$this->userPermissionMapper->deleteAll($budget->id);
|
||||||
$userPermissions = [];
|
$userPermissions = [];
|
||||||
$users[$this->userId] = UserPermission::PERMISSION_MANAGE;
|
foreach ($users as $user) {
|
||||||
foreach ($users as $user => $permission) {
|
if ($user['user'] === $this->userId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$userPermission = new UserPermission();
|
$userPermission = new UserPermission();
|
||||||
$userPermission->setBudgetId($budget->getId());
|
$userPermission->setBudgetId($budget->getId());
|
||||||
$userPermission->setUserId($user);
|
$userPermission->setUserId($user['user']);
|
||||||
$userPermission->setPermission($permission);
|
$userPermission->setPermission($user['permission']);
|
||||||
array_push($userPermissions, $this->userPermissionMapper->insert($userPermission));
|
array_push($userPermissions, $this->userPermissionMapper->insert($userPermission));
|
||||||
}
|
}
|
||||||
|
$userPermission = new UserPermission();
|
||||||
|
$userPermission->setBudgetId($budget->getId());
|
||||||
|
$userPermission->setUserId($this->userId);
|
||||||
|
$userPermission->setPermission(UserPermission::PERMISSION_MANAGE);
|
||||||
|
array_push($userPermissions, $this->userPermissionMapper->insert($userPermission));
|
||||||
$budget->setUsers($userPermissions);
|
$budget->setUsers($userPermissions);
|
||||||
} else {
|
} else {
|
||||||
$budget->setUsers($userPermissionMapper->findAllByBudgetId($budget->getId()));
|
$budget->setUsers($userPermissionMapper->findAllByBudgetId($budget->getId()));
|
||||||
}
|
}
|
||||||
foreach ($users as $user => $permission) {
|
|
||||||
$this->logger->error("User: $user Permission: $permission");
|
|
||||||
}
|
|
||||||
return new DataResponse($budget);
|
return new DataResponse($budget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,20 @@
|
||||||
<h2>{{ budget.id ? 'Edit' : 'Add' }} Budget</h2>
|
<h2>{{ budget.id ? 'Edit' : 'Add' }} Budget</h2>
|
||||||
<input v-model="budget.name" type="text" placeholder="Name" title="Name" />
|
<input v-model="budget.name" type="text" placeholder="Name" title="Name" />
|
||||||
<textarea v-model="budget.description" placeholder="Description" title="Description"></textarea>
|
<textarea v-model="budget.description" placeholder="Description" title="Description"></textarea>
|
||||||
|
<div class="sharing">
|
||||||
|
<h3>Sharing</h3>
|
||||||
|
<input v-model="user" v-on:keyup.enter="addPermission()" type="test" placeholde="User" title="User" />
|
||||||
|
<ul v-if="budget.users" class="sharing-users">
|
||||||
|
<li v-for="user in budget.users">
|
||||||
|
<span v-if="user.user">
|
||||||
|
{{ user.user }}
|
||||||
|
</span>
|
||||||
|
<span v-if="user.permission">
|
||||||
|
: {{ user.permission }}
|
||||||
|
</span>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
<button @click="saveBudget()">Save Budget</button>
|
<button @click="saveBudget()">Save Budget</button>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="loading" class="icon-loading"></div>
|
<div v-if="loading" class="icon-loading"></div>
|
||||||
|
@ -18,16 +32,26 @@ export default {
|
||||||
},
|
},
|
||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
saving: false
|
saving: false,
|
||||||
|
user: undefined
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
budget: Object
|
budget: Object,
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
loading: state => state.budget === undefined || state.saving
|
loading: state => state.budget === undefined || state.saving
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
addPermission() {
|
||||||
|
const user = this.user
|
||||||
|
this.user = undefined;
|
||||||
|
this.budget.users = this.budget.users.filter(u => u.user != user)
|
||||||
|
this.budget.users.push({
|
||||||
|
"user": user,
|
||||||
|
"permission": 2
|
||||||
|
})
|
||||||
|
},
|
||||||
saveBudget() {
|
saveBudget() {
|
||||||
this.saving = true;
|
this.saving = true;
|
||||||
this.$store.dispatch("budgetFormSaveClicked", this.budget);
|
this.$store.dispatch("budgetFormSaveClicked", this.budget);
|
||||||
|
|
|
@ -11,8 +11,10 @@ export default {
|
||||||
},
|
},
|
||||||
data: function() {
|
data: function() {
|
||||||
return {
|
return {
|
||||||
budget: {}
|
budget: {
|
||||||
};
|
users: []
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -147,6 +147,14 @@ export default new Vuex.Store({
|
||||||
router.push({ name: "categoryDetails", params: { id: response.data.id } })
|
router.push({ name: "categoryDetails", params: { id: response.data.id } })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
deleteCategoryClicked({ commit, state }, categoryId) {
|
||||||
|
axios.delete(OC.generateUrl(`/apps/twigs/api/v1.0/categories/${categoryId}`))
|
||||||
|
.then((response) => {
|
||||||
|
commit('setCurrentCategory', undefined)
|
||||||
|
commit('deleteCategory', response.data)
|
||||||
|
router.push({ name: "budgetDetails", params: { id: state.currentBudget } })
|
||||||
|
})
|
||||||
|
},
|
||||||
addTransactionClicked({ commit }) {
|
addTransactionClicked({ commit }) {
|
||||||
router.push({ name: "newTransaction" })
|
router.push({ name: "newTransaction" })
|
||||||
},
|
},
|
||||||
|
@ -250,6 +258,11 @@ export default new Vuex.Store({
|
||||||
[data.categoryId]: data.sum
|
[data.categoryId]: data.sum
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
deleteCategory(state, category) {
|
||||||
|
state.categories = [
|
||||||
|
...state.categories.filter(c => c.id !== category.id),
|
||||||
|
]
|
||||||
|
},
|
||||||
addTransaction(state, transaction) {
|
addTransaction(state, transaction) {
|
||||||
state.transactions = [
|
state.transactions = [
|
||||||
...state.transactions.filter(t => t.id !== transaction.id),
|
...state.transactions.filter(t => t.id !== transaction.id),
|
||||||
|
|
Loading…
Reference in a new issue