Completed
Push — master ( 7146d7...8dcd63 )
by Maxence
02:55
created

MembersController::level()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 17
nc 2
nop 3
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 OCP\AppFramework\Http\DataResponse;
30
31
class MembersController extends BaseController {
32
33
34
	/**
35
	 * @NoAdminRequired
36
	 * @NoSubAdminRequired
37
	 *
38
	 * @param string $uniqueId
39
	 * @param string $name
40
	 *
41
	 * @return DataResponse
42
	 */
43 View Code Duplication
	public function add($uniqueId, $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...
44
45
		try {
46
			$data = $this->membersService->addMember($uniqueId, $name);
47
		} catch (\Exception $e) {
48
			return $this->fail(
49
				[
50
					'circle_id' => $uniqueId,
51
					'user_id'   => $name,
52
					'name'      => $this->miscService->getDisplayName($name, true),
53
					'error'     => $e->getMessage()
54
				]
55
			);
56
		}
57
58
		return $this->success(
59
			[
60
				'circle_id' => $uniqueId,
61
				'user_id'   => $name,
62
				'name'      => $this->miscService->getDisplayName($name, true),
63
				'members'   => $data
64
			]
65
		);
66
	}
67
68
69
	/**
70
	 * @NoAdminRequired
71
	 * @NoSubAdminRequired
72
	 *
73
	 * @param $uniqueId
74
	 * @param string $name
75
	 *
76
	 * @return DataResponse
77
	 */
78 View Code Duplication
	public function importFromGroup($uniqueId, $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...
79
80
		try {
81
			$data = $this->membersService->importMembersFromGroup($uniqueId, $name);
82
		} catch (\Exception $e) {
83
			return $this->fail(
84
				[
85
					'circle_id' => $uniqueId,
86
					'user_id'   => $name,
87
					'name'      => $this->miscService->getDisplayName($name, true),
88
					'error'     => $e->getMessage()
89
				]
90
			);
91
		}
92
93
		return $this->success(
94
			[
95
				'circle_id' => $uniqueId,
96
				'user_id'   => $name,
97
				'name'      => $this->miscService->getDisplayName($name, true),
98
				'members'   => $data
99
			]
100
		);
101
	}
102
103
104
	/**
105
	 * @NoAdminRequired
106
	 * @NoSubAdminRequired
107
	 *
108
	 * @param string $uniqueId
109
	 * @param string $member
110
	 * @param int $level
111
	 *
112
	 * @return DataResponse
113
	 */
114
	public function level($uniqueId, $member, $level) {
115
116
		try {
117
			$data = $this->membersService->levelMember($uniqueId, $member, $level);
118
		} catch (\Exception $e) {
119
			return
120
				$this->fail(
121
					[
122
						'circle_id' => $uniqueId,
123
						'user_id'   => $member,
124
						'name'      => $this->miscService->getDisplayName($member, true),
125
						'level'     => $level,
126
						'error'     => $e->getMessage()
127
					]
128
				);
129
		}
130
131
		return $this->success(
132
			[
133
				'circle_id' => $uniqueId,
134
				'user_id'   => $member,
135
				'name'      => $this->miscService->getDisplayName($member, true),
136
				'level'     => $level,
137
				'members'   => $data,
138
			]
139
		);
140
	}
141
142
143
	/**
144
	 * @NoAdminRequired
145
	 * @NoSubAdminRequired
146
	 *
147
	 * @param string $uniqueId
148
	 * @param string $member
149
	 *
150
	 * @return DataResponse
151
	 */
152 View Code Duplication
	public function remove($uniqueId, $member) {
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...
153
154
		try {
155
			$data = $this->membersService->removeMember($uniqueId, $member);
156
		} catch (\Exception $e) {
157
			return
158
				$this->fail(
159
					[
160
						'circle_id' => $uniqueId,
161
						'user_id'   => $member,
162
						'name'      => $this->miscService->getDisplayName($member, true),
163
						'error'     => $e->getMessage()
164
					]
165
				);
166
		}
167
168
		return $this->success(
169
			[
170
				'circle_id' => $uniqueId,
171
				'user_id'   => $member,
172
				'name'      => $this->miscService->getDisplayName($member, true),
173
				'members'   => $data,
174
			]
175
		);
176
	}
177
178
179
}
180
181