changeset 4236:27ed6f709195

Remove unused systemconf.feature_colours from backend * Remove unused routes for `/system/style/{feature}/{attr}`, including the namespace `systemconf` from the schema. This has previously be replaced by a more general mechanism, which is already used by the frontend.
author Bernhard Reiter <bernhard@intevation.de>
date Wed, 21 Aug 2019 16:17:46 +0200
parents 966d7eb6d99b
children c831dcad8a10
files pkg/controllers/routes.go pkg/controllers/system.go pkg/models/system.go schema/auth.sql schema/default_sysconfig.sql schema/gemma.sql
diffstat 6 files changed, 5 insertions(+), 155 deletions(-) [+]
line wrap: on
line diff
--- a/pkg/controllers/routes.go	Wed Aug 21 15:59:15 2019 +0200
+++ b/pkg/controllers/routes.go	Wed Aug 21 16:17:46 2019 +0200
@@ -88,15 +88,6 @@
 		Handle: setSystemSettings,
 	})).Methods(http.MethodPut)
 
-	api.Handle("/system/style/{feature}/{attr}", any(&JSONHandler{
-		Handle: getFeatureStyle,
-	})).Methods(http.MethodGet)
-
-	api.Handle("/system/style/{feature}/{attr}", any(&JSONHandler{
-		Input:  func(*http.Request) interface{} { return new(models.Colour) },
-		Handle: setFeatureStyle,
-	})).Methods(http.MethodPut)
-
 	// Password resets.
 	api.Handle("/users/passwordreset", &JSONHandler{
 		Input:  func(*http.Request) interface{} { return new(models.PWResetUser) },
--- a/pkg/controllers/system.go	Wed Aug 21 15:59:15 2019 +0200
+++ b/pkg/controllers/system.go	Wed Aug 21 16:17:46 2019 +0200
@@ -4,7 +4,7 @@
 // SPDX-License-Identifier: AGPL-3.0-or-later
 // License-Filename: LICENSES/AGPL-3.0.txt
 //
-// Copyright (C) 2018 by via donau
+// Copyright (C) 2018, 2019 by via donau
 //   – Österreichische Wasserstraßen-Gesellschaft mbH
 // Software engineering by Intevation GmbH
 //
@@ -37,13 +37,6 @@
 )
 
 const (
-	getFeatureColourSQL = `SELECT r,g,b,a
-FROM systemconf.feature_colours
-WHERE feature_name = $1 AND style_attr = $2`
-	setFeatureColourSQL = `UPDATE systemconf.feature_colours
-SET (r, g, b, a) = ($3, $4, $5, $6)
-WHERE feature_name = $1 AND style_attr = $2`
-
 	getSettingsSQL = `
 SELECT config_key, config_val
 FROM sys_admin.system_config`
@@ -384,82 +377,3 @@
 	}
 	return
 }
-
-// Map/Feature style end points
-
-func getFeatureStyle(
-	_ interface{},
-	req *http.Request,
-	db *sql.Conn,
-) (jr JSONResult, err error) {
-
-	feature := mux.Vars(req)["feature"]
-	attr := mux.Vars(req)["attr"]
-
-	c := models.Colour{}
-	err = db.QueryRowContext(
-		req.Context(),
-		getFeatureColourSQL,
-		feature, attr,
-	).Scan(&c.R, &c.G, &c.B, &c.A)
-
-	switch {
-	case err == sql.ErrNoRows:
-		err = JSONError{
-			Code:    http.StatusNotFound,
-			Message: "Requestes style not found.",
-		}
-		return
-	case err != nil:
-		return
-	}
-
-	jr.Result = &struct {
-		Colour models.Colour `json:"colour"`
-		Code   string        `json:"code"`
-	}{c, fmt.Sprintf("rgba(%d, %d, %d, %g)", c.R, c.G, c.B, c.A)}
-	return
-}
-
-func setFeatureStyle(
-	input interface{},
-	req *http.Request,
-	db *sql.Conn,
-) (jr JSONResult, err error) {
-
-	feature := mux.Vars(req)["feature"]
-	attr := mux.Vars(req)["attr"]
-
-	c := input.(*models.Colour)
-	if !c.IsValid() {
-		err = JSONError{http.StatusBadRequest, "error: invalid colours"}
-		return
-	}
-
-	var res sql.Result
-	res, err = db.ExecContext(
-		req.Context(),
-		setFeatureColourSQL,
-		feature, attr,
-		c.R, c.G, c.B, c.A)
-
-	if err != nil {
-		return
-	}
-
-	if n, err2 := res.RowsAffected(); err2 == nil && n == 0 {
-		err = JSONError{
-			Code:    http.StatusNotFound,
-			Message: "Requestes style not found.",
-		}
-		return
-	}
-
-	jr = JSONResult{
-		Code: http.StatusCreated,
-		Result: struct {
-			Result string `json:"result"`
-		}{"success"},
-	}
-	return
-}
--- a/pkg/models/system.go	Wed Aug 21 15:59:15 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-// This is Free Software under GNU Affero General Public License v >= 3.0
-// without warranty, see README.md and license for details.
-//
-// SPDX-License-Identifier: AGPL-3.0-or-later
-// License-Filename: LICENSES/AGPL-3.0.txt
-//
-// Copyright (C) 2018 by via donau
-//   – Österreichische Wasserstraßen-Gesellschaft mbH
-// Software engineering by Intevation GmbH
-//
-// Author(s):
-//  * Sascha Wilde <sascha.wilde@intevation.de>
-//  * Sascha Teichmann <sascha.teichmann@intevation.de>
-
-package models
-
-type (
-	Colour struct {
-		R int     `json:"r"`
-		G int     `json:"g"`
-		B int     `json:"b"`
-		A float32 `json:"a"`
-	}
-)
-
-func isByteRange(i int) bool {
-	return i >= 0 && i < 256
-}
-
-func (c Colour) IsValid() bool {
-	return isByteRange(c.R) &&
-		isByteRange(c.G) &&
-		isByteRange(c.B) &&
-		c.A >= 0 && c.A <= 1
-}
--- a/schema/auth.sql	Wed Aug 21 15:59:15 2019 +0200
+++ b/schema/auth.sql	Wed Aug 21 16:17:46 2019 +0200
@@ -25,10 +25,9 @@
 --
 -- Privileges for waterway_user
 --
-GRANT USAGE ON SCHEMA public, users, waterway, systemconf, sys_admin, caching TO waterway_user;
+GRANT USAGE ON SCHEMA public, users, waterway, sys_admin, caching TO waterway_user;
 GRANT SELECT ON ALL TABLES IN SCHEMA public, users, waterway TO waterway_user;
 GRANT SELECT, UPDATE, DELETE, INSERT ON ALL TABLES IN SCHEMA caching TO waterway_user;
-GRANT SELECT ON systemconf.feature_colours TO waterway_user;
 GRANT SELECT ON sys_admin.system_config TO waterway_user;
 GRANT UPDATE (pw, map_extent, email_address) ON users.list_users
     TO waterway_user;
@@ -61,7 +60,6 @@
 GRANT USAGE ON SCHEMA sys_admin TO sys_admin;
 GRANT SELECT ON ALL TABLES IN SCHEMA sys_admin TO sys_admin;
 GRANT INSERT, UPDATE ON sys_admin.system_config TO sys_admin;
-GRANT UPDATE ON systemconf.feature_colours TO sys_admin;
 GRANT UPDATE ON sys_admin.published_services TO sys_admin;
 GRANT INSERT, DELETE, UPDATE ON sys_admin.password_reset_requests TO sys_admin;
 
--- a/schema/default_sysconfig.sql	Wed Aug 21 15:59:15 2019 +0200
+++ b/schema/default_sysconfig.sql	Wed Aug 21 16:17:46 2019 +0200
@@ -4,12 +4,14 @@
 -- SPDX-License-Identifier: AGPL-3.0-or-later
 -- License-Filename: LICENSES/AGPL-3.0.txt
 
--- Copyright (C) 2018 by via donau
+-- Copyright (C) 2018, 2019 by via donau
 --   – Österreichische Wasserstraßen-Gesellschaft mbH
 -- Software engineering by Intevation GmbH
 
 -- Author(s):
 --  * Sascha Wilde <wilde@intevation.de>
+--  * Bernhard Reiter <bernhard.reiter@intevation.de>
+--  * Fadi Abbund <fadi.abbud@intevation.de>
 
 BEGIN;
 
@@ -18,12 +20,6 @@
 --
 
 --
--- Style definitions
---
-INSERT INTO systemconf.feature_colours VALUES ('Bottlenecks', 'stroke', 250, 40, 255, 1);
-INSERT INTO systemconf.feature_colours VALUES ('Bottlenecks', 'fill', 255, 37, 196, 0.14);
-
---
 -- Settings
 --
 INSERT INTO sys_admin.system_config VALUES ('ecdis_wms_url', 'https://service.d4d-portal.info/wms/');
--- a/schema/gemma.sql	Wed Aug 21 15:59:15 2019 +0200
+++ b/schema/gemma.sql	Wed Aug 21 16:17:46 2019 +0200
@@ -388,20 +388,6 @@
 ALTER TABLE internal.user_profiles ADD
     country char(2) NOT NULL REFERENCES users.responsibility_areas;
 
-
--- Namespace for system wide configuration
-CREATE SCHEMA systemconf
-    CREATE TABLE feature_colours (
-        feature_name varchar,
-        style_attr varchar,
-        r int NOT NULL CHECK (r >= 0 AND r < 256),
-        g int NOT NULL CHECK (g >= 0 AND g < 256),
-        b int NOT NULL CHECK (b >= 0 AND b < 256),
-        a numeric NOT NULL CHECK (a >= 0 AND a <= 1),
-        PRIMARY KEY (feature_name, style_attr)
-    )
-;
-
 -- Namespace for waterway data that can change in a running system
 CREATE SCHEMA waterway