Skip to content

Commit

Permalink
Merge pull request #6091 from OCHA-DAP/dev-hdx-9010
Browse files Browse the repository at this point in the history
Dev hdx 9010
  • Loading branch information
danmihaila authored Aug 30, 2023
2 parents 4050279 + da30894 commit 3de3efb
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ckanext-hdx_org_group/ckanext/hdx_org_group/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def _modify_group_schema(self, schema):
tk.get_converter('convert_to_extras')],
'custom_org': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')],
'request_membership': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')],
'closed_organization': [tk.get_validator('hdx_boolean_string_converter'), tk.get_converter('convert_to_extras')],
'customization': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')],
# 'less': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')],
'visualization_config': [tk.get_validator('ignore_missing'), tk.get_converter('convert_to_extras')],
Expand Down Expand Up @@ -165,6 +166,7 @@ def db_to_form_schema(self):
'user_survey_url': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')],
'custom_org': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')],
'request_membership': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')],
'closed_organization': [tk.get_converter('convert_from_extras'), tk.get_validator('boolean_validator')],
'customization': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')],
# 'less': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')],
'visualization_config': [tk.get_converter('convert_from_extras'), tk.get_validator('ignore_missing')],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,129 @@ def test_user_survey_url_controller(self):
except Exception as ex:
assert False
assert True





class TestClosedOrganizationAPI(org_group_base.OrgGroupBaseTest):

@classmethod
def _load_plugins(cls):
hdx_test_base.load_plugin('ytp_request hdx_org_group hdx_theme')

@classmethod
def _get_action(cls, action_name):
return tk.get_action(action_name)

def test_create_org_api(self):
context_sysadmin = {'model': model, 'session': model.Session, 'user': 'testsysadmin',
'allow_partial_update': True}
new_org_dict = {
'name': 'test_org_dd',
'title': 'Test Org D',
'org_url': 'www.exampleorganization.org',
'description': 'just a simple description',
'hdx_org_type': ORGANIZATION_TYPE_LIST[0][1]
}
try:
org_dict = self._get_action('organization_create')(context_sysadmin, new_org_dict)
assert org_dict.get('name') == 'test_org_dd'
assert org_dict.get('closed_organization') == False
except Exception as ex:
assert False

edit_org_dict = {
'id': org_dict.get('id'),
'name': 'test_org_dd',
'title': 'Test Org DD',
'org_url': 'www.exampleorganization.org',
'description': 'just a simple description',
'hdx_org_type': ORGANIZATION_TYPE_LIST[0][1]
}
try:
org_dict = self._get_action('organization_update')(context_sysadmin, edit_org_dict)
org_dict = self._get_action('organization_show')(context_sysadmin, edit_org_dict)
assert org_dict.get('title') == 'Test Org DD'
assert org_dict.get('closed_organization') == False
except Exception as ex:
assert False

def test_closed_organization_api(self):
context_usr = {'model': model, 'session': model.Session, 'user': 'tester', 'allow_partial_update': True}
context_sysadmin = {'model': model, 'session': model.Session, 'user': 'testsysadmin'}
new_org_dict = {
'name': 'test_org_d',
'title': 'Test Org D',
'closed_organization': 'true',
'org_url': 'www.exampleorganization.org',
'description': 'just a simple description',
'hdx_org_type': ORGANIZATION_TYPE_LIST[0][1]
}
try:
org_dict = self._get_action('organization_create')(context_sysadmin, new_org_dict)
assert 'closed_organization' in org_dict
assert org_dict.get('closed_organization') == True
except Exception as ex:
assert False

try:
_org_update_dict = {
'id': org_dict.get('id'),
'name': org_dict.get('name'),
'title': org_dict.get('title'),
'closed_organization': 'false',
'org_url': org_dict.get('org_url'),
'description': org_dict.get('description'),
'hdx_org_type': org_dict.get('hdx_org_type'),
}
self._get_action('organization_update')(context_sysadmin, _org_update_dict)
org_updated_dict = self._get_action('organization_show')(context_sysadmin, {'id': org_dict.get('id')})
assert 'closed_organization' in org_updated_dict
assert org_updated_dict.get('closed_organization') == False
except Exception as ex:
assert False

try:
member_dict = {'id': org_dict.get('id'), 'username': 'tester', 'role': 'admin'}
self._get_action('organization_member_create')(context_sysadmin, member_dict)
_org_dict = self._get_action('organization_show')(context_sysadmin, {'id': org_dict.get('id')})
assert True
except Exception as ex:
assert False

try:
_org_update_dict = {
'id': org_updated_dict.get('id'),
'name': org_updated_dict.get('name'),
'title': org_updated_dict.get('title'),
'org_url': org_updated_dict.get('org_url'),
'description': org_updated_dict.get('description'),
'hdx_org_type': org_updated_dict.get('hdx_org_type'),
}
self._get_action('organization_update')(context_usr, _org_update_dict)
org_updated_dict = self._get_action('organization_show')(context_sysadmin, {'id': _org_update_dict.get('id')})
assert 'closed_organization' in org_updated_dict
assert org_updated_dict.get('closed_organization') == False
except Exception as ex:
assert False

try:
_org_update_dict = {
'id': org_dict.get('id'),
'name': org_dict.get('name'),
'closed_organization': 'true',
'title': org_dict.get('title'),
'org_url': org_dict.get('org_url'),
'description': org_dict.get('description'),
'hdx_org_type': org_dict.get('hdx_org_type'),
}
self._get_action('organization_update')(context_usr, _org_update_dict)
org_updated_dict = self._get_action('organization_show')(context_sysadmin, {'id': org_dict.get('id')})
assert 'closed_organization' in org_updated_dict
assert org_updated_dict.get('closed_organization') == True
except Exception as ex:
assert False

assert True

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ $(document).ready(function(){
}
});

$('#field-closed_organization').change(function(e){
const $closed_organization = $('#field-closed_organization');
const $hidden_closed_organization = $("#hidden-field-closed_organization");
if ($closed_organization.is(':checked')){
$hidden_closed_organization.val('true');
} else {
$hidden_closed_organization.val('false');
}
});

$('#visualization-select').change(function(){
var this_div = $(this).val();
$('.visualization-div').hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ $('document').ready(function(){
}
});
}

// filter out "closed" items
const not_closed_results = results.filter(obj => {return obj.title.includes("(closed)")===false; });
return {
'q': query,
'termList': termList,
'modifiedQ': modifiedQ,
'results': results
'results': not_closed_results
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,26 @@ <h1 class="h1-title uppercase">
<div id="customization-trigger" class="org-control-container">
<label class="control-label" for="field-custom_org" style="display: inline-block;">{{ _("Use custom organisation page") }}</label>
<div class="controls" style="display:inline-block">
<input type="checkbox" {{ custom_org_checked }} name="custom_org" id="field-custom_org" value="1" style="margin-left:10px; margin-bottom:5px; margin-top:-10px;"/>
<input type="checkbox" {{ custom_org_checked }} name="custom_org" id="field-custom_org" value="1" style="margin-left:10px; margin-bottom:5px; margin-top:0px;"/>
</div>
</div>

{% set closed_organization = h.hdx_get_extras_element(data, value_key="closed_organization") or "false" %}
{% set closed_organization_checked = 'checked="checked"' if closed_organization=='true' else '' %}
<div id="closed_organization-trigger" class="org-control-container">
<div class="control-group control-full org-control field-with-info" style="min-height:30px">
<label class="control-label" for="field-closed_organization" style="display: inline-block;">{{ _('This organization is closed/inactive') }}</label>
<div class="controls" style="display:inline-block">
<input type="hidden" name="closed_organization" id="hidden-field-closed_organization" value="{{ closed_organization }}" />
<input type="checkbox" {{ closed_organization_checked }} id="field-closed_organization" style="margin-left:10px; margin-bottom:5px; margin-top:0px;"/>
</div>
</div>
<div class="org-control-info info-field" style="margin-top:0px;">
<div class="org-info-label">
{{_('Check the checkbox if the organization is no longer in use/active in HDX ')}}
</div>
</div>
</div>

{% set request_membership = h.hdx_get_extras_element(data, value_key="request_membership") or "true" %}
{% set request_membership_checked = 'checked="checked"' if request_membership=='true' else '' %}
Expand All @@ -101,7 +117,7 @@ <h1 class="h1-title uppercase">
<label class="control-label" for="field-request_membership" style="display: inline-block;">{{ _('Allow Membership Requests') }}</label>
<div class="controls" style="display:inline-block">
<input type="hidden" name="request_membership" id="hidden-field-request_membership" value="{{ request_membership }}" />
<input type="checkbox" {{ request_membership_checked }} id="field-request_membership" style="margin-left:10px; margin-bottom:5px; margin-top:-10px;"/>
<input type="checkbox" {{ request_membership_checked }} id="field-request_membership" style="margin-left:10px; margin-bottom:5px; margin-top:0px;"/>
</div>
</div>
<div class="org-control-info info-field" style="margin-top:0px;">
Expand All @@ -119,7 +135,6 @@ <h1 class="h1-title uppercase">
</div>
</div>


<div id="customization-fields" class="{% if not custom_org %}element-invisible{% endif %}">
<div class="org-control-container">
<h1 class="h1-title uppercase">
Expand Down

0 comments on commit 3de3efb

Please sign in to comment.