Skip to content
Snippets Groups Projects
Commit 145fbf50 authored by Cam Saul's avatar Cam Saul
Browse files

Add validity checks for Field.field_type in Clojure land; remove "None"

option from UI
parent e119e73d
No related branches found
No related tags found
No related merge requests found
......@@ -52,31 +52,31 @@ CorvusServices.factory('AppState', ['$rootScope', '$routeParams', '$q', '$locati
service.model.currentUser = result;
// add isMember(orgSlug) method to the object
service.model.currentUser.isMember = function (orgSlug) {
return this.org_perms.some(function (org_perm) {
service.model.currentUser.isMember = function(orgSlug) {
return this.org_perms.some(function(org_perm) {
return org_perm.organization.slug === orgSlug;
});
};
// add isAdmin(orgSlug) method to the object
service.model.currentUser.isAdmin = function (orgSlug) {
return this.org_perms.some(function (org_perm) {
service.model.currentUser.isAdmin = function(orgSlug) {
return this.org_perms.some(function(org_perm) {
return org_perm.organization.slug === orgSlug && org_perm.admin;
}) || this.is_superuser;
};
// add memberOf() method to the object enumerating Organizations user is member of
service.model.currentUser.memberOf = function () {
return this.org_perms.map(function (org_perm) {
service.model.currentUser.memberOf = function() {
return this.org_perms.map(function(org_perm) {
return org_perm.organization;
});
};
// add adminOf() method to the object enumerating Organizations user is admin of
service.model.currentUser.adminOf = function () {
return this.org_perms.filter(function (org_perm) {
service.model.currentUser.adminOf = function() {
return this.org_perms.filter(function(org_perm) {
return org_perm.admin;
}).map(function (org_perm) {
}).map(function(org_perm) {
return org_perm.organization;
});
};
......@@ -417,9 +417,6 @@ CorvusServices.service('CorvusCore', ['$resource', 'User', function($resource, U
'name': 'Zip Code'
}];
this.field_field_types = [{
'id': null,
'name': 'None'
}, {
'id': 'info',
'name': 'Information'
}, {
......@@ -831,4 +828,4 @@ CoreServices.factory('PermissionViolation', ['$resource', '$cookies', function($
},
});
}]);
}]);
\ No newline at end of file
(ns metabase.models.field
(:require [korma.core :refer :all]
[metabase.api.common :refer [check]]
[metabase.db :refer :all]
(metabase.models [database :refer [Database]])
[metabase.util :as util]))
......@@ -62,25 +63,38 @@
:dimension
:info})
(defn- check-valid-field-type
"Assert that FIELD-TYPE is valid value for `Field.field_type`, or throw a 400."
[field-type]
(check (contains? field-types (keyword field-type))
[400 (format "Invalid field_type: '%s'" (when field-type
(name field-type)))]))
(defentity Field
(table :metabase_field))
(defmethod post-select Field [_ {:keys [table_id] :as field}]
(util/assoc* field
:table (delay (sel :one 'metabase.models.table/Table :id table_id))
:db (delay @(:db @(:table <>)))
:can_read (delay @(:can_read @(:table <>)))
:can_write (delay @(:can_write @(:table <>)))))
:table (delay (sel :one 'metabase.models.table/Table :id table_id))
:db (delay @(:db @(:table <>)))
:can_read (delay @(:can_read @(:table <>)))
:can_write (delay @(:can_write @(:table <>)))))
(defmethod pre-insert Field [_ field]
(let [defaults {:created_at (util/new-sql-timestamp)
:updated_at (util/new-sql-timestamp)
:active true
(let [defaults {:created_at (util/new-sql-timestamp)
:updated_at (util/new-sql-timestamp)
:active true
:preview_display true
:field_type :info
:position 0}]
:field_type :info
:position 0}]
(let [{:keys [field_type base_type special_type] :as field} (merge defaults field)]
(check-valid-field-type field_type)
(assoc field
:base_type (name base_type)
:special_type (when special_type (name special_type))
:field_type (name field_type)))))
(defmethod pre-update Field [_ field]
(when (contains? field :field_type)
(check-valid-field-type (:field_type field)))
field)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment