Suche nach Usern Teil 1

This commit is contained in:
holger.trampe 2021-06-30 21:02:04 +02:00
parent a34e8f0e88
commit 3b2544e7ac
8 changed files with 78 additions and 13 deletions

View File

@ -8,6 +8,7 @@ return [
# AGENCY
['name' => 'agency#show', 'url' => '/getagencydata', 'verb' => 'GET'],
['name' => 'agency#updateagencydata', 'url' => '/updateagencydata', 'verb' => 'PUT'],
['name' => 'agency#getagencycontributors', 'url' => '/getagencycontributors', 'verb' => 'GET'],
# GROUPS
['name' => 'group#getagencygroups', 'url' => '/getagencygroups', 'verb' => 'GET'],
['name' => 'group#addagencygroup', 'url' => '/addagencygroup', 'verb' => 'PUT'],

View File

@ -37,7 +37,7 @@ class AgencyManager {
/**
* getAgencyByUser
*
* Return the Agency-ID by filtering the id from default agency-group, ex: agency_1 -> 1 (int)
* Return the complete Agency-Data by filtering the id from default agency-group, ex: agency_1 -> 1 (int)
*
*/
public function getAgencyByUser(){
@ -52,6 +52,20 @@ class AgencyManager {
return $this->agencyMapper->getAgencyByGId($agency_group_id);
#return $agency_group_id;
}
/**
* Return only the AgencyGroupId
*/
public function getAgencyGIdByUser(){
$groups = $this->groupManager->getUserGroups($this->userSession->getUser());
$agency_group_id = "";
foreach($groups as $group){
if(str_contains($group->getGId(), 'agencymaingroupid_')){
$agency_group_id_array = explode("_", strval($group->getGId()));
$agency_group_id = $agency_group_id_array[0]."_".$agency_group_id_array[1];
}
}
return $agency_group_id;
}
// Return an random Id-Ele for generating single IDs
public function generateRandomId($length = 6) {
@ -63,4 +77,22 @@ class AgencyManager {
}
return $randomString;
}
/**
* Returns all users of an Agency by filtering the Main Agency Group Id out
*
* Returns an Array of IUser-Objects. Filtering is by logged User
*/
public function getagencycontributors(){
$group = $this->groupManager->get($this->getAgencyGIdByUser());
$users = $group->getUsers();
$return_users = array();
// Creating a nice User-JSON-Array
foreach($users as $user){
#array_push($return_users, array("displayName" => $user->getDisplayName(), "uid" => $user->getUID(), "lastLogin" => $user->getLastLogin()));
array_push($return_users, $user->getDisplayName());
}
return $return_users;
}
}

View File

@ -94,4 +94,11 @@ class AgencyController extends Controller {
});
}
/**
* @NoAdminRequired
*/
public function getagencycontributors(){
return $this->agencyManager->getagencycontributors();
}
}

View File

@ -3,6 +3,8 @@ declare(strict_types=1);
namespace OCA\Agency\Controller;
use Exception;
use OCP\IRequest;
use OCP\IGroupManager;
use OCP\AppFramework\Http\DataResponse;
@ -106,12 +108,11 @@ class GroupController extends Controller {
$searchGroupId = $this->agencymanager->getAgencyByUser()->getAgencygid();
$result = false;
# If user is in the same Agency, then delete
# If user is in the same Agency, then delete is possible - check permissions!
# TODO: Hier noch einbauen, dass die Rechte geprüft werden!
if(str_contains($todel->getGID(), $searchGroupId)) {
# TODO: Hier das löschen der GroupPermission mit verwalten, wenn eine Gruppe gelöscht wird!
// $todel->delete();
$result = true;
$this->grouppermissionservice->remove($todel->getGID());
$todel->delete();
}
return $result;
}

View File

@ -34,11 +34,10 @@ class GroupPermissionMapper extends QBMapper {
return $this->findEntity($qb);
}
public function remove(int $id) {
$db = $this->db->getQueryBuilder();
$db->delete($this->getTableName())
->where($db->expr()->eq('id', $query->createNamedParameter($id)));
return $this->findEntity($qb);
public function remove(string $gid) {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->getTableName())
->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid)));
return $qb->execute();
}
}

View File

@ -51,9 +51,9 @@ class GroupPermissionService {
}
}
public function remove(int $id){
public function remove(string $gid){
try {
return $this->mapper->remove($id);
return $this->mapper->remove($gid);
} catch(Exception $e) {
$this->handleException($e);
}

View File

@ -24,19 +24,27 @@
The GroupId is {{ group.gid }} <br>
<span v-if="group.isDefault">Ist default</span>
<span v-else>Nicht default</span>
<hr>
<!-- SHAREING -->
<Multiselect
placeholder="Suche"
:options="agencyContributor" />
</b-card-body>
</b-collapse>
</b-card>
</template>
<script>
// import { generateUrl, generateOcsUrl } from '@nextcloud/router'
import { generateUrl } from '@nextcloud/router'
import axios from '@nextcloud/axios'
import Permission from './Permission'
import { Multiselect } from '@nextcloud/vue'
export default {
name: 'Group',
components: {
Permission,
Multiselect,
},
// Properties of Group-Elements
props: {
@ -53,9 +61,22 @@ export default {
return {
// Main Group-ID for all Accordions
groupDefId: 'acc_groupele_',
contributors: [],
}
},
computed: {
agencyContributor() {
return this.contributors
},
},
created() {
this.getAgencyContributor()
},
methods: {
async getAgencyContributor() {
const response = await axios.get(generateUrl('/apps/agency/getagencycontributors'))
this.contributors = response.data
},
// Toggle the Group-Accordion-Element
accordionToggle(ele) {
this.$root.$emit('bv::toggle::collapse', this.groupDefId + ele)
@ -67,6 +88,7 @@ export default {
this.$emit('updateGroupData')
},
delGroup(id) {
// Confirm Window
this.$confirm({
message: 'Möchten Sie die Gruppe ' + this.group.name + ' löschen?',
button: {

View File

@ -9,6 +9,7 @@ import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'
import 'bootstrap-vue/dist/bootstrap-vue-icons.min.css'
import VueConfirmDialog from 'vue-confirm-dialog'
// import { translate, translatePlural } from '@nextcloud/l10n'
// import store from './store'
Vue.use(VueRouter)
@ -16,6 +17,8 @@ Vue.use(VueFormulate, {
plugins: [de],
locale: 'de',
})
// Vue.prototype.t = translate
// Vue.prototype.n = translatePlural
Vue.use(VueConfirmDialog)
Vue.use(BootstrapVue)
Vue.use(BootstrapVueIcons)