Skip to content

Commit

Permalink
Add permission for Kew RGB 25cm data
Browse files Browse the repository at this point in the history
  • Loading branch information
paulthatjazz committed Sep 10, 2024
1 parent 4872c11 commit 2d6f9c4
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 13 deletions.
5 changes: 4 additions & 1 deletion app/javascript/controllers/projects_controller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class extends Controller {
projectTeamId: Number,
projectTeamName: String,
projectDefraHedgerowPermission: Boolean,
projectKewRgb25cmPermission: Boolean,
backButtonPath: String,
dbModels: Object,
}
Expand All @@ -21,6 +22,7 @@ export default class extends Controller {
declare readonly projectTeamIdValue: number
declare readonly projectTeamNameValue: string
declare readonly projectDefraHedgerowPermissionValue: boolean
declare readonly projectKewRgb25cmPermissionValue: boolean
declare readonly backButtonPathValue: string
declare readonly dbModelsValue: DBModels

Expand All @@ -35,7 +37,8 @@ export default class extends Controller {
teamName={this.projectTeamNameValue}
permissions={
{
DefraHedgerows: this.projectDefraHedgerowPermissionValue
DefraHedgerows: this.projectDefraHedgerowPermissionValue,
KewRgb25cm: this.projectKewRgb25cmPermissionValue
}
}
/>,
Expand Down
26 changes: 15 additions & 11 deletions app/javascript/projects/layer_palette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { iconForLayerType } from "./util"
import { CompiledDatasetRecord } from './saved_dataset'
import { designations } from './modelling/designations'
import { IMDProperties } from './reify_layer/imd'
import { ProjectPermissions } from './project_editor'

interface AddLayerButtonProps {
prototype: Layer
Expand Down Expand Up @@ -41,9 +42,10 @@ interface LayerPaletteProps {
dbModels: DBModels
getTeamDatasets: () => Promise<Array<CompiledDatasetRecord>>
teamName: string
permissions: ProjectPermissions
}

export const LayerPalette = ({ addLayer, hide, dbModels, getTeamDatasets, teamName }: LayerPaletteProps) => {
export const LayerPalette = ({ addLayer, hide, dbModels, getTeamDatasets, teamName, permissions }: LayerPaletteProps) => {

const [teamDatasets, setTeamDatasets] = React.useState<CompiledDatasetRecord[]>([])

Expand Down Expand Up @@ -414,16 +416,18 @@ export const LayerPalette = ({ addLayer, hide, dbModels, getTeamDatasets, teamNa
}
{
<Section title="Aerial/Satellite imagery">
<AddLayerButton
addLayer={addLayer}
prototype={{
layerName: "rgb:full_mosaic_3857",
type: "GeoserverLayer",
name: "RGB 25cm",
visible: true,
opacity: 1,
}}
/>
{permissions.KewRgb25cm &&
<AddLayerButton
addLayer={addLayer}
prototype={{
layerName: "rgb:full_mosaic_3857",
type: "GeoserverLayer",
name: "RGB 25cm",
visible: true,
opacity: 1,
}}
/>
}
{
dbModels.mapTileLayers.map(layer => (
<AddLayerButton
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/projects/project_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export enum Tab {

export interface ProjectPermissions {
DefraHedgerows: boolean
KewRgb25cm: boolean
}

interface ProjectEditorProps {
Expand Down Expand Up @@ -176,6 +177,7 @@ export function ProjectEditor({ projectId, projectSource, backButtonPath, dbMode
dbModels={dbModels}
getTeamDatasets={() => getDatasets(teamId)}
teamName={teamName}
permissions={permissions}
/>
}
{
Expand Down
9 changes: 9 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ def defra_hedgerow_permission
tp ? tp.enabled : false
end

def kew_rgb25cm_permission
p = Permission.find_by(name: 'kew_rgb25cm')
puts "p: #{p}"
return false unless p

tp = team.team_permissions.find_by(permission: p)
tp ? tp.enabled : false
end

end
1 change: 1 addition & 0 deletions app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
data-projects-project-team-name-value="<%= @project.team.name %>"
data-projects-project-source-value="<%= @project.source.to_json %>"
data-projects-project-defra-hedgerow-permission-value="<%= @project.defra_hedgerow_permission %>"
data-projects-project-kew-rgb25cm-permission-value="<%= @project.kew_rgb25cm_permission %>"
data-projects-back-button-path-value="<%= team_projects_path(@project.team) %>"
data-projects-db-models-value="<%= render partial: "defs", formats: [:json] %>"
></div>
18 changes: 18 additions & 0 deletions db/migrate/20240910120054_add_rgb25cm_permission.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class AddRgb25cmPermission < ActiveRecord::Migration[6.1]

def up
permission = Permission.find_or_create_by(name: 'kew_rgb25cm')

Team.all.each do |team|
TeamPermission.find_or_create_by(team: team, permission: permission, enabled: false)
end
end

def down
permission = Permission.find_by(name: 'kew_rgb25cm')
if permission
TeamPermission.where(permission: permission).destroy_all
permission.destroy
end
end
end
2 changes: 1 addition & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2024_06_11_101639) do
ActiveRecord::Schema.define(version: 2024_09_10_120054) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down

0 comments on commit 2d6f9c4

Please sign in to comment.