Completed
Pull Request — master (#94)
by Maxence
02:28
created

GroupsController::add()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 27
Code Lines 15

Duplication

Lines 27
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 27
loc 27
rs 8.8571
c 1
b 0
f 0
cc 3
eloc 15
nc 3
nop 2
1
<?php
2
/**
3
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2017
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OCA\Circles\Controller;
28
29
use OCA\Circles\Exceptions\LinkedGroupNotAllowedException;
30
use OCP\AppFramework\Http\DataResponse;
31
32
class GroupsController extends BaseController {
33
34
35
	/**
36
	 * @NoAdminRequired
37
	 * @NoSubAdminRequired
38
	 *
39
	 * @param int $id
40
	 * @param string $name
41
	 *
42
	 * @return DataResponse
43
	 * @throws LinkedGroupNotAllowedException
44
	 */
45 View Code Duplication
	public function add($id, $name) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
		if (!$this->configService->isLinkedGroupsAllowed()) {
47
			throw new LinkedGroupNotAllowedException(
48
				$this->l10n->t("Linked Groups are not allowed on this Nextcloud")
49
			);
50
		}
51
52
		try {
53
			$data = $this->groupsService->linkGroup($id, $name);
54
		} catch (\Exception $e) {
55
			return $this->fail(
56
				[
57
					'circle_id' => $id,
58
					'name'      => $name,
59
					'error'     => $e->getMessage()
60
				]
61
			);
62
		}
63
64
		return $this->success(
65
			[
66
				'circle_id' => $id,
67
				'name'      => $name,
68
				'groups'    => $data
69
			]
70
		);
71
	}
72
73
74
	/**
75
	 * @NoAdminRequired
76
	 * @NoSubAdminRequired
77
	 *
78
	 * @param $id
79
	 * @param $group
80
	 * @param $level
81
	 *
82
	 * @return DataResponse
83
	 */
84 View Code Duplication
	public function level($id, $group, $level) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
86
		try {
87
			$data = $this->groupsService->levelGroup($id, $group, $level);
88
		} catch (\Exception $e) {
89
			return
90
				$this->fail(
91
					[
92
						'circle_id' => $id,
93
						'name'      => $group,
94
						'level'     => $level,
95
						'error'     => $e->getMessage()
96
					]
97
				);
98
		}
99
100
		return $this->success(
101
			[
102
				'circle_id' => $id,
103
				'name'      => $group,
104
				'level'     => $level,
105
				'groups'   => $data,
106
			]
107
		);
108
	}
109
110
111
	/**
112
	 * @NoAdminRequired
113
	 * @NoSubAdminRequired
114
	 *
115
	 * @param int $id
116
	 * @param string $group
117
	 *
118
	 * @return DataResponse
119
	 * @throws LinkedGroupNotAllowedException
120
	 */
121 View Code Duplication
	public function remove($id, $group) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
122
		if (!$this->configService->isLinkedGroupsAllowed()) {
123
			throw new LinkedGroupNotAllowedException(
124
				$this->l10n->t("Linked Groups are not allowed on this Nextcloud")
125
			);
126
		}
127
128
		try {
129
			$data = $this->groupsService->unlinkGroup($id, $group);
130
		} catch (\Exception $e) {
131
			return
132
				$this->fail(
133
					[
134
						'circle_id' => $id,
135
						'name'      => $group,
136
						'error'     => $e->getMessage()
137
					]
138
				);
139
		}
140
141
		return $this->success(
142
			[
143
				'circle_id' => $id,
144
				'name'      => $group,
145
				'groups'    => $data,
146
			]
147
		);
148
	}
149
150
151
}
152
153