Skip to content

Commit

Permalink
Resolve #261 and #497: Improve handling of resources (#644)
Browse files Browse the repository at this point in the history
* Resolve #261:
- Improve the feature of attaching/detaching resources
- Treat archived resources as if they were deleted

* Resolve PR #644 feedback; rework permissions functionality; do other tweaks

* Resolve further PR review feedback
  • Loading branch information
seav authored and oliverroick committed Sep 8, 2016
1 parent 288bbce commit c190062
Show file tree
Hide file tree
Showing 41 changed files with 1,231 additions and 338 deletions.
6 changes: 5 additions & 1 deletion cadasta/config/permissions/data-collector.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"action": ["resource.*"],
"object": ["resource/$organization/$project/*"]
},

{
"effect": "deny",
"action": ["resource.unarchive"],
"object": ["resource/$organization/$project/*"]
},
{
"effect": "allow",
"action": ["spatial.*", "spatial.resources.*"],
Expand Down
5 changes: 5 additions & 0 deletions cadasta/config/permissions/org-admin.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"effect": "allow",
"action": ["resource.*"],
"object": ["resource/$organization/*/*"]
},
{
"effect": "deny",
"action": ["resource.unarchive"],
"object": ["resource/$organization/*/*"]
}
]
}
5 changes: 5 additions & 0 deletions cadasta/config/permissions/project-manager.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
"effect": "allow",
"action": ["resource.*"],
"object": ["resource/$organization/$project/*"]
},
{
"effect": "deny",
"action": ["resource.unarchive"],
"object": ["resource/$organization/$project/*"]
}
]
}
27 changes: 17 additions & 10 deletions cadasta/core/static/css/main.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 17 additions & 3 deletions cadasta/core/static/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1051,14 +1051,17 @@ textarea.form-control {
text-transform: uppercase;
font-size: 12px;
opacity: 0.7;
padding: 4px 24px;
//padding: 4px 24px;
background: $body-bg;
}
> tbody > tr.linked > td:hover {
cursor: pointer;
}
.btn-sm {
min-width: 90px;
min-width: 80px !important;
}
.table-condensed .btn-sm {
min-width: 60px !important;
}
div.org-logo {
padding: 4px 0;
Expand Down Expand Up @@ -1300,7 +1303,7 @@ div.add-btn-btm { // add party link at bottom of table
}
}

/* =Alerts
/* =Alerts and labels
-------------------------------------------------------------- */

.alert {
Expand Down Expand Up @@ -1346,6 +1349,17 @@ div.add-btn-btm { // add party link at bottom of table
@include alert-variant($alert-danger-bg, $alert-danger-border, $alert-danger-text);
}

.label {
font-size: 11px;
font-weight: 500;
vertical-align: middle;
}

h1.label {
font-size: 14px;
}


@media (max-width: $screen-sm-max) {
.alert {
max-width: none;
Expand Down
14 changes: 7 additions & 7 deletions cadasta/core/static/css/resources.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/* =Resources
-------------------------------------------------------------- */


div.resource-60 {
float: left;
padding: 0 10px;
}
div.resource-60 {
}

div.resource-text {
margin-left: 90px;
display: table-cell;
margin-left: 80px;
word-wrap: break-word;
}

Expand All @@ -23,6 +21,8 @@ ul.resource-actions > li {
margin: 12px 0;
&:first-child {
padding-left: 0;
border-right: 1px solid $table-border-color;
}
&+li {
border-left: 1px solid $table-border-color;
}
}
15 changes: 15 additions & 0 deletions cadasta/organization/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.core.urlresolvers import reverse
from django.conf import settings
from django.db import models
from django_countries.fields import CountryField
Expand Down Expand Up @@ -225,6 +226,20 @@ def __str__(self):
def __repr__(self):
return str(self)

@property
def ui_class_name(self):
return _("Project")

@property
def ui_detail_url(self):
return reverse(
'organization:project-dashboard',
kwargs={
'organization': self.organization.slug,
'project': self.slug,
},
)

def save(self, *args, **kwargs):
if ((self.country is None or self.country == '') and
self.extent is not None):
Expand Down
11 changes: 11 additions & 0 deletions cadasta/organization/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ def test_can_create_private(self):
project = ProjectFactory.create(access='private')
assert not project.public()

def test_ui_class_name(self):
project = ProjectFactory.create()
assert project.ui_class_name == "Project"

def test_ui_detail_url(self):
project = ProjectFactory.create()
assert project.ui_detail_url == (
'/organizations/{org}/projects/{prj}/'.format(
org=project.organization.slug,
prj=project.slug))


class ProjectRoleTest(UserTestCase):
def setUp(self):
Expand Down
43 changes: 40 additions & 3 deletions cadasta/party/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Party models."""

from core.models import RandomIDModel
from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.gis.db import models
from django.contrib.postgres.fields import JSONField
Expand Down Expand Up @@ -115,6 +116,21 @@ def __str__(self):
def __repr__(self):
return str(self)

@property
def ui_class_name(self):
return _("Party")

@property
def ui_detail_url(self):
return reverse(
'parties:detail',
kwargs={
'organization': self.project.organization.slug,
'project': self.project.slug,
'party': self.id,
},
)


@fix_model_for_attributes
@permissioned_model
Expand Down Expand Up @@ -268,13 +284,34 @@ class TutelaryMeta:
)

def __str__(self):
return "<TenureRelationship: <{party}> {type} <{su}>>".format(
party=self.party.name, su=self.spatial_unit.get_type_display(),
type=self.tenure_type.label)
return "<TenureRelationship: {}>".format(self.name)

def __repr__(self):
return str(self)

@property
def name(self):
return "<{party}> {type} <{su}>".format(
party=self.party.name,
su=self.spatial_unit.name,
type=self.tenure_type.label,
)

@property
def ui_class_name(self):
return _("Relationship")

@property
def ui_detail_url(self):
return reverse(
'parties:relationship_detail',
kwargs={
'organization': self.project.organization.slug,
'project': self.project.slug,
'relationship': self.id,
},
)


class TenureRelationshipType(models.Model):
"""Defines allowable tenure types."""
Expand Down
31 changes: 31 additions & 0 deletions cadasta/party/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ def test_adding_attributes(self):
})
assert party.attributes['description'] == 'Mad Hatters Tea Party'

def test_ui_class_name(self):
party = PartyFactory.create()
assert party.ui_class_name == "Party"

def test_ui_detail_url(self):
party = PartyFactory.create()
assert party.ui_detail_url == (
'/organizations/{org}/projects/{prj}/records/parties/{id}/'.format(
org=party.project.organization.slug,
prj=party.project.slug,
id=party.id))


class PartyRelationshipTest(UserTestCase):

Expand Down Expand Up @@ -177,6 +189,25 @@ def test_left_and_right_project_ids(self):
party__project=project
)

def test_name(self):
tenurerel = TenureRelationshipFactory.create()
assert tenurerel.name == "<{party}> {type} <{su}>".format(
party=tenurerel.party.name,
type=tenurerel.tenure_type.label,
su=tenurerel.spatial_unit.get_type_display())

def test_ui_class_name(self):
tenurerel = TenureRelationshipFactory.create()
assert tenurerel.ui_class_name == "Relationship"

def test_ui_detail_url(self):
tenurerel = TenureRelationshipFactory.create()
assert tenurerel.ui_detail_url == (
'/organizations/{org}/projects/{prj}/relationships/{id}/'.format(
org=tenurerel.project.organization.slug,
prj=tenurerel.project.slug,
id=tenurerel.id))


class TenureRelationshipTypeTest(UserTestCase):
"""Test TenureRelationshipType."""
Expand Down
Loading

0 comments on commit c190062

Please sign in to comment.