Browse Source

Adding group API visibility control

Alan Hardman 3 years ago
parent
commit
d256c79f1e
6 changed files with 45 additions and 5 deletions
  1. 10 0
      app/controller/admin.php
  2. 2 2
      app/controller/api/user.php
  3. 1 0
      app/dict/en.ini
  4. 24 2
      app/view/admin/groups/edit.html
  5. 6 0
      db/16.04.13.sql
  6. 2 1
      db/database.sql

+ 10 - 0
app/controller/admin.php

@@ -455,6 +455,16 @@ class Admin extends \Controller {
 				$group->save();
 				$this->_printJson(array("changed" => 1));
 				break;
+			case "change_task_color":
+				$group->task_color = trim($f3->get("POST.value"));
+				$group->save();
+				$this->_printJson(array("changed" => 1));
+				break;
+			case "change_api_visibility":
+				$group->api_visible = (int)!!$f3->get("POST.value");
+				$group->save();
+				$this->_printJson(array("changed" => 1));
+				break;
 		}
 	}
 

+ 2 - 2
app/controller/api/user.php

@@ -19,7 +19,7 @@ class User extends \Controller\Api {
 		}
 
 		$result = array(
-				"id" =>$group_id,
+				"id" => $group_id,
 				"name" => $user->name,
 				"username" => $user->username,
 				"email" => $user->email
@@ -98,7 +98,7 @@ class User extends \Controller\Api {
 		$result = $user->paginate(
 				$f3->get("GET.offset") / $pagLimit,
 				$pagLimit,
-				"deleted_date IS NULL AND role = 'group'"
+				"deleted_date IS NULL AND role = 'group' AND api_visible != '0'"
 			);
 
 		$groups = array();

+ 1 - 0
app/dict/en.ini

@@ -278,6 +278,7 @@ group_name_saved=Group name saved
 manager=Manager
 set_as_manager=Set as Manager
 add_to_group=Add to Group
+api_visible=Visible to API
 no_groups_exist=No groups exist.
 new_sprint=New Sprint
 edit_sprint=Edit Sprint

+ 24 - 2
app/view/admin/groups/edit.html

@@ -48,6 +48,21 @@
 					<button type="submit" class="btn btn-sm btn-primary">{{ @dict.add_to_group }}</button>
 				</div>
 			</form>
+			<form>
+				<div class="checkbox">
+					<label>
+						<check if="{{ @group.api_visible }}">
+							<true>
+								<input type="checkbox" id="chk-api-visibility" name="value" value="1" checked>
+							</true>
+							<false>
+								<input type="checkbox" id="chk-api-visibility" name="value" value="1">
+							</false>
+						</check>
+						{{ @dict.api_visible }}
+					</label>
+				</div>
+			</form>
 		</div>
 	</div>
 	<include href="blocks/footer.html" />
@@ -58,7 +73,7 @@ $(function(){
 		if($(this).val().length > 0) {
 			$.post('{{ @BASE }}/admin/groups/ajax',{
 				action: 'change_title',
-				group_id: parseInt('{{ @group.id }}'),
+				group_id: '{{ @group.id }}',
 				name: $(this).val()
 			}, function(data) {
 				$('.saved').show();
@@ -73,7 +88,7 @@ $(function(){
 		if(confirm('Are you sure you want to remove this user?')) {
 			$.post('{{ @BASE }}/admin/groups/ajax', {
 				action: 'remove_member',
-				group_id: parseInt('{{ @group.id }}'),
+				group_id: '{{ @group.id }}',
 				user_id: $li.data('user-id')
 			}, function(data) {
 				if(data.deleted) {
@@ -91,6 +106,13 @@ $(function(){
 		});
 		e.preventDefault();
 	});
+	$('#chk-api-visibility').change(function(e) {
+		$.post('{{ @BASE }}/admin/groups/ajax',{
+			action: 'change_api_visibility',
+			group_id: '{{ @group.id }}',
+			value: $(this).prop('checked') + 0
+		}, function() {}, 'json');
+	});
 });
 </script>
 </body>

+ 6 - 0
db/16.04.13.sql

@@ -0,0 +1,6 @@
+# Add api_visible column to user table
+ALTER TABLE `user`
+	ADD COLUMN `api_visible` TINYINT(1) UNSIGNED DEFAULT 1 NOT NULL AFTER `api_key`;
+
+# Update version
+UPDATE `config` SET `value` = '16.04.13' WHERE `attribute` = 'version';

+ 2 - 1
db/database.sql

@@ -18,6 +18,7 @@ CREATE TABLE `user` (
 	`avatar_filename` varchar(64) DEFAULT NULL,
 	`options` blob NULL,
 	`api_key` varchar(40) NULL,
+	`api_visible` tinyint(1) unsigned NOT NULL DEFAULT '1',
 	`created_date` datetime NOT NULL,
 	`deleted_date` datetime DEFAULT NULL,
 	PRIMARY KEY (`id`),
@@ -305,4 +306,4 @@ CREATE TABLE `config` (
 	UNIQUE KEY `attribute` (`attribute`)
 );
 
-INSERT INTO `config` (`attribute`, `value`) VALUES ('version', '16.02.05');
+INSERT INTO `config` (`attribute`, `value`) VALUES ('version', '16.04.13');