Added status to program.
authorLennard de Rijk <ljvderijk@gmail.com>
Sat, 31 Jan 2009 13:48:48 +0000
changeset 1107 a878188e225c
parent 1106 e14b0995cf29
child 1108 64acc3c02ad1
Added status to program. Also added a new access_check and changed the program edit template to the basic one without edit timeline button. Changed the program menu to show more helpful links like Edit Timeline. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/models/program.py
app/soc/templates/soc/program/edit.html
app/soc/views/helper/access.py
app/soc/views/models/program.py
--- a/app/soc/models/program.py	Sat Jan 31 12:59:52 2009 +0000
+++ b/app/soc/models/program.py	Sat Jan 31 13:48:48 2009 +0000
@@ -100,12 +100,19 @@
                                  required=True, collection_name="program",
                                  verbose_name=ugettext('Timeline'))
 
-  #: Whether the program is enabled
-  is_enabled = db.BooleanProperty(default=False,
-      verbose_name=ugettext('Is Enabled'))
-  is_enabled.help_text = ugettext(
-      'Field used to indicate if a Program is enabled at all, and as such'
-      '  accessible to non-developers.')
+  #: Status of the program
+  #: Invisible: Program Stealth-Mode Visible to Hosts and Devs only
+  #: Visible: Visible to everyone.
+  #: Inactive: Not visible in sidebar but can be reached for date retention
+  #: Invalid: Not visible or editable by anyone
+  status = db.StringProperty(required=True, default='invisible',
+      verbose_name=ugettext('Program Status'),
+      choices=['invisible', 'visible', 'inactive', 'invalid'])
+  status.example_text = ugettext(
+      '<tt>Invisible: Program Stealth-Mode Visible to Hosts and Devs only.<br/>'
+      'Visible: Visible to everyone.<br/>'
+      'Inactive: Not visible in sidebar, not editable.<br/>'
+      'Invalid: Not visible or editable by anyone.</tt>')
 
   #: Whether the slots allocations are visible
   allocations_visible = db.BooleanProperty(default=False,
--- a/app/soc/templates/soc/program/edit.html	Sat Jan 31 12:59:52 2009 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,21 +0,0 @@
-{% extends "soc/models/edit.html" %}
-{% comment %}
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-  http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-{% endcomment %}
-
-{% block submit_buttons %}
-{{ block.super }}
-<td>
- <input type="button" onclick="location.href='/timeline/edit/{{ entity_suffix }}'" value="Edit Timeline"/>
-</td>
-{% endblock %}
--- a/app/soc/views/helper/access.py	Sat Jan 31 12:59:52 2009 +0000
+++ b/app/soc/views/helper/access.py	Sat Jan 31 13:48:48 2009 +0000
@@ -45,8 +45,9 @@
 from soc.logic.models.request import logic as request_logic
 from soc.logic.models.role import logic as role_logic
 from soc.logic.models.site import logic as site_logic
+from soc.logic.models.program import logic as program_logic
 from soc.logic.models.user import logic as user_logic
-from soc.logic.models.program import logic as program_logic
+from soc.logic.models.timeline import logic as timeline_logic
 from soc.views import helper
 from soc.views import out_of_band
 from soc.views.helper import redirects
@@ -600,10 +601,10 @@
     key_fields = program_logic.getKeyFieldsFromDict(django_args)
     program = program_logic.getFromFields(**key_fields)
 
-    if not program:
+    if not program or program.status == 'invalid':
       self.deny(django_args)
 
-    new_args = { 'scope_path': program.scope_path }
+    new_args = {'scope_path': program.scope_path }
     self.checkIsHost(new_args)
 
   @allowDeveloper
@@ -890,9 +891,9 @@
     # is public or not, probably involving analysing it's scope or such.
     self.allow(django_args)
 
-  @allowIfCheckPasses('checkIsHost')
-  def checkIsProgramActive(self, django_args):
-    """Checks whether a program is active
+  @allowIfCheckPasses('checkIsHostForProgram')
+  def checkIsProgramVisible(self, django_args):
+    """Checks whether a program is visible.
     """
 
     if 'entity' in django_args:
@@ -904,7 +905,7 @@
     if not program:
       self.deny(django_args)
 
-    if program.is_enabled:
+    if program.status == 'visible':
       return
 
     context = django_args.get('context', {})
@@ -915,3 +916,23 @@
 
     raise out_of_band.AccessViolation(DEF_DEV_LOGOUT_LOGIN_MSG_FMT,
                                       context=context)
+
+
+  def checkCanEditTimeline(self, django_args):
+    """Allows developers and hosts for this program's timeline to edit it.
+    """
+    time_line_keyname = django_args['scope_path']
+    timeline_entity = timeline_logic.getFromKeyName(time_line_keyname)
+
+    if not timeline_entity:
+      # timeline does not exists so deny
+      self.deny(django_args)
+
+    splitkeyname = time_line_keyname.rsplit('/')
+
+    fields = {'scope_path' : splitkeyname[0],
+        'workflow' : splitkeyname[1],
+        'link_id' : splitkeyname[2],
+        }
+
+    return self.checkIsHostForProgram(fields)
--- a/app/soc/views/models/program.py	Sat Jan 31 12:59:52 2009 +0000
+++ b/app/soc/views/models/program.py	Sat Jan 31 13:48:48 2009 +0000
@@ -58,7 +58,7 @@
     rights['show'] = ['allow']
     rights['create'] = ['checkIsHost']
     rights['edit'] = ['checkIsHostForProgram']
-    rights['delete'] = ['checkIsHostForProgram']
+    rights['delete'] = ['checkIsDeveloper']
 
     new_params = {}
     new_params['logic'] = soc.logic.models.program.logic
@@ -70,10 +70,9 @@
     new_params['name'] = "Program"
     new_params['sidebar_grouping'] = 'Programs'
 
-    new_params['edit_template'] = 'soc/program/edit.html'
-
     new_params['extra_dynaexclude'] = ['timeline']
 
+    # TODO add clean field to check for uniqueness in link_id and scope_path
     new_params['create_extra_dynafields'] = {
         'description': forms.fields.CharField(widget=helper.widgets.TinyMCE(
             attrs={'rows':10, 'cols':40})),
@@ -137,28 +136,45 @@
     logic = params['logic']
     rights = params['rights']
 
-    entities = logic.getForLimitAndOffset(1000)
+    # only get all invisible and visible programs
+    fields = {'status':['invisible', 'visible']}
+    entities = logic.getForFields(fields)
 
-    doc_params = document_view.view.getParams()
+    #TODO(ljvderijk) Add timeline dependent entries
+
     menus = []
 
     rights.setCurrentUser(id, user)
     filter_args = {}
 
     for entity in entities:
-      filter_args['entity'] = entity
-      try:
-        rights.doCheck('checkIsProgramActive', filter_args, [])
-      except out_of_band.Error:
-        continue
+      items = []
 
-      items = document_view.view.getMenusForScope(entity, params)
+      if entity.status == 'visible':
+        # show the documents for this program, even for not logged in users
+        items += document_view.view.getMenusForScope(entity, params)
 
       try:
-        rights.doCachedCheck('checkIsHost', {}, [])
-        items += [(redirects.getEditRedirect(entity, params),'Edit','any_access')]
+        # check if the current user is a host for this program
+        rights.doCachedCheck('checkIsHostForProgram', 
+            {'scope_path' : entity.scope_path,
+            'link_id' : entity.link_id,
+            'workflow' : entity.workflow}, [])
+
+        if entity.status == 'invisible':
+          # still add the document links so hosts can see how it looks like
+          items += document_view.view.getMenusForScope(entity, params)
+
+        # add link to edit Program Profile
+        items += [(redirects.getEditRedirect(entity, params),
+            'Edit Program Profile','any_access')]
+        # add link to edit Program Timeline
+        items += [(redirects.getEditRedirect(entity, {'url_name': 'timeline'}),
+            "Edit Program Timeline", 'any_access')]
+        # add link to create a new Program Document
         items += [(redirects.getCreateDocumentRedirect(entity, 'program'),
           "Create new document", 'any_access')]
+
       except out_of_band.Error:
         pass