Exemplo n.º 1
0
def completeApplication(record_entity, record_logic, org_entity, role_name):
  """Sends out invites to the main and backup admin specified in the
  OrgAppRecord entity and completes the application.

  Args:
    record_entity: OrgAppRecord entity
    record_logic: OrgAppRecord Logic instance
    org_entity: The newly created Organization
    role_name: internal name for the role requested
  """

  from soc.logic.models.request import logic as request_logic

  properties = {
      'role': role_name,
      'group': org_entity,
      'message': DEF_INVITE_MSG,
      'status': 'group_accepted',
      }

  for admin in [record_entity.main_admin, record_entity.backup_admin]:
    if not admin:
      continue

    properties['user'] = admin
    request_logic.updateOrCreateFromFields(properties)

  fields = {'status': 'completed'}
  record_logic.updateEntityProperties(record_entity, fields)
Exemplo n.º 2
0
    def invitePost(self, request, context, params, group_entity, **kwargs):
        """Handles the POST request concerning the view that creates an invite
    for attaining a certain Role.

    Args:
      request: the standard Django HTTP request object
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      group_entity: Group entity which this invite is from
      kwargs: the Key Fields for the specified entity
    """

        # get the request view parameters and populate the form using POST data
        request_params = request_view.view.getParams()
        form = request_params['invite_form'](request.POST)

        if not form.is_valid():
            # return the invalid form response
            return self._constructResponse(request,
                                           entity=None,
                                           context=context,
                                           form=form,
                                           params=request_params)

        # collect the cleaned data from the valid form
        _, form_fields = soc.views.helper.forms.collectCleanedFields(form)

        # create the fields for the new request entity
        request_fields = {
            'user': form_fields['user_id'],
            'group': group_entity,
            'role': params['logic'].role_name,
            'status': 'group_accepted'
        }

        if not request_logic.isValidNewRequest(request_fields,
                                               params['logic']):
            # not a valid invite
            context['error_message'] = self.DEF_INVITE_ERROR_MSG_FMT % (params)
            return super(View, self)._constructResponse(request,
                                                        entity=None,
                                                        context=context,
                                                        form=form,
                                                        params=request_params)

        # create the request entity
        request_logic.updateOrCreateFromFields(request_fields)

        group_view = params.get('group_view')

        if not group_view:
            return http.HttpResponseRedirect('/')
        else:
            # redirect to the requests list
            return http.HttpResponseRedirect(
                redirects.getListRequestsRedirect(group_entity,
                                                  group_view.getParams()))
Exemplo n.º 3
0
    def requestPost(self, request, context, params, group_entity, **kwargs):
        """Handles the POST request concerning the creation of a request
    to attain a role.

    Args:
      request: the standard Django HTTP request object
      context: dictionary containing the context for this view
      params: a dict with params for this View
      group_entity: the Group entity this request is for
      kwargs: the Key Fields for the specified entity
    """

        # get the request view parameters and populate the form using POST data
        request_params = request_view.view.getParams()
        form = request_params['request_form'](request.POST)

        if not form.is_valid():
            # return the invalid form response
            return self._constructResponse(request,
                                           entity=None,
                                           context=context,
                                           form=form,
                                           params=request_params)

        _, fields = soc.views.helper.forms.collectCleanedFields(form)

        # set the fields for the new request
        user_entity = user_logic.logic.getForCurrentAccount()

        request_fields = {
            'user': user_entity,
            'group': group_entity,
            'message': fields['message'],
            'role': params['logic'].role_name,
            'status': 'new'
        }

        if not request_logic.isValidNewRequest(request_fields,
                                               params['logic']):
            # not a valid request
            context['error_message'] = self.DEF_REQUEST_ERROR_MSG_FMT % (
                params)
            return super(View, self)._constructResponse(request,
                                                        entity=None,
                                                        context=context,
                                                        form=form,
                                                        params=request_params)

        # create the request entity
        request_logic.updateOrCreateFromFields(request_fields)

        # redirect to requests overview
        return http.HttpResponseRedirect('/user/requests')
Exemplo n.º 4
0
  def invitePost(self, request, context, params, group_entity, **kwargs):
    """Handles the POST request concerning the view that creates an invite
    for attaining a certain Role.

    Args:
      request: the standard Django HTTP request object
      page_name: the page name displayed in templates as page and header title
      params: a dict with params for this View
      group_entity: Group entity which this invite is from
      kwargs: the Key Fields for the specified entity
    """

    # get the request view parameters and populate the form using POST data
    request_params = request_view.view.getParams()
    form = request_params['invite_form'](request.POST)

    if not form.is_valid():
      # return the invalid form response
      return self._constructResponse(request, entity=None, context=context,
          form=form, params=request_params)

    # collect the cleaned data from the valid form
    _, form_fields = soc.views.helper.forms.collectCleanedFields(form)

    # create the fields for the new request entity
    request_fields = {
        'user': form_fields['user_id'],
        'group': group_entity,
        'role': params['logic'].role_name,
        'status': 'group_accepted'}

    if not request_logic.isValidNewRequest(request_fields, params['logic']):
      # not a valid invite
      context['error_message'] = self.DEF_INVITE_ERROR_MSG_FMT % (
          params)
      return super(View, self)._constructResponse(request, entity=None,
          context=context, form=form, params=request_params)

    # create the request entity
    request_logic.updateOrCreateFromFields(request_fields)

    group_view = params.get('group_view')

    if not group_view:
      return http.HttpResponseRedirect('/')
    else:
      # redirect to the requests list
      return http.HttpResponseRedirect(
          redirects.getListRequestsRedirect(group_entity, 
                                            group_view.getParams()))
Exemplo n.º 5
0
  def requestPost(self, request, context, params, group_entity, **kwargs):
    """Handles the POST request concerning the creation of a request
    to attain a role.

    Args:
      request: the standard Django HTTP request object
      context: dictionary containing the context for this view
      params: a dict with params for this View
      group_entity: the Group entity this request is for
      kwargs: the Key Fields for the specified entity
    """

    # get the request view parameters and populate the form using POST data
    request_params = request_view.view.getParams()
    form = request_params['request_form'](request.POST)

    if not form.is_valid():
      # return the invalid form response
      return self._constructResponse(request, entity=None, context=context,
          form=form, params=request_params)

    _, fields = soc.views.helper.forms.collectCleanedFields(form)

    # set the fields for the new request
    user_entity = user_logic.logic.getCurrentUser()

    request_fields = {
        'user': user_entity,
        'group' : group_entity,
        'message': fields['message'],
        'role' : params['logic'].role_name,
        'status' : 'new'}

    if not request_logic.isValidNewRequest(request_fields, params['logic']):
      # not a valid request
      context['error_message'] = self.DEF_REQUEST_ERROR_MSG_FMT % (
          params)
      return super(View, self)._constructResponse(request, entity=None,
          context=context, form=form, params=request_params)

    # create the request entity
    request_logic.updateOrCreateFromFields(request_fields)

    # redirect to requests overview
    return http.HttpResponseRedirect('/user/requests')
Exemplo n.º 6
0
def completeApplication(record_entity, record_logic, org_entity, role_name):
    """Sends out invites to the main and backup admin specified in the
  OrgAppRecord entity and completes the application.

  Args:
    record_entity: OrgAppRecord entity
    record_logic: OrgAppRecord Logic instance
    org_entity: The newly created Organization
    role_name: internal name for the role requested
  """

    from soc.logic.models.request import logic as request_logic

    properties = {"role": role_name, "group": org_entity, "message": DEF_INVITE_MSG, "status": "group_accepted"}

    for admin in [record_entity.main_admin, record_entity.backup_admin]:
        if not admin:
            continue

        properties["user"] = admin
        request_logic.updateOrCreateFromFields(properties)

    fields = {"status": "completed"}
    record_logic.updateEntityProperties(record_entity, fields)
Exemplo n.º 7
0
  def setUp(self):
    """Set up required for the view tests.
    """

    # Create a user for sponsor
    email = "*****@*****.**"
    account = users.User(email=email)
    link_id = 'a_sponsor_user'
    name = 'A Sponsor User'
    sponsor_user_properties = {
        'account': account,
        'link_id': link_id,
        'name': name,
        }
    self.sponsor_user = user_logic.updateOrCreateFromFields(
        sponsor_user_properties)

    # Create sponsor role for a_sponsor_user
    link_id = 'a_sponsor'
    name = link_id
    phone = '01234567'
    contact_postalcode = 'A postalcode'
    description = 'A description'
    contact_country = 'United States'
    short_name = 'AS'
    contact_city = 'A city'
    home_page = 'http://www.asponsor.com'
    email = '*****@*****.**'
    sponsor_properties = {
        'link_id': link_id,
        'name': name,
        'short_name': short_name,
        'founder': self.sponsor_user,
        'phone': phone,
        'description': description,
        'contact_country': contact_country,
        'contact_city': contact_city,
        'contact_street': 'A Street',
        'contact_postalcode': contact_postalcode,
        'home_page': home_page,
        'email': email,
        }
    self.sponsor = sponsor_logic.updateOrCreateFromFields(sponsor_properties)

    # Create a timeline for a program
    timeline_properties = {
        'link_id': 'a_program',
        'scope_path': 'a_sponsor',
        'scope': self.sponsor,
          }
    self.timeline = timeline_logic.updateOrCreateFromFields(
      timeline_properties)

    # Create a program for a_sponsor
    program_properties = {
        'link_id': 'a_program',
        'scope': self.sponsor,
        'scope_path': self.sponsor.key().id_or_name(),
        'name': 'A Program 2010',
        'short_name': 'AP2010',
        'group_label': 'AP',
        'description': 'This is the program for AP2010.',
        'apps_tasks_limit': 42,
        'slots': 42,
        'timeline': self.timeline,
        'status': 'visible',
        }
    self.program = program_logic.updateOrCreateFromFields(program_properties)

    # Create another user for org admin who is also the founder of the org
    email = '*****@*****.**'
    account = users.User(email=email)
    link_id = 'an_oa_user'
    name = 'An Org Admin User'
    oa_user_properties = {
        'account': account,
        'link_id': link_id,
        'name': name,
        'agreed_to_tos': True,
        }
    self.oa_user = user_logic.updateOrCreateFromFields(
        oa_user_properties)

    # create an org for the program
    org_properties = {
        'link_id': 'an_org',
        'scope': self.program,
        'scope_path': self.program.key().id_or_name(),
        'name': 'An Organization',
        'short_name': 'An Org' ,
        'founder': self.oa_user,
        'home_page': 'http://anorg.com',
        'email': '*****@*****.**',
        'description': 'An Organization Description',
        'contact_street': 'An Organization Street',
        'contact_city': 'An Organization City',
        'contact_country': 'United Kingdom',
        'contact_postalcode': '0123456 AnO',
        'phone': '1-555-BANANA',
        'status': 'active',
        }
    self.org = org_logic.updateOrCreateFromFields(org_properties)

    request_properties = {
        'role': 'gsoc_org_admin',
        'user': self.oa_user,
        'group': self.org,
        'message': 'An Invitation Request Message',
        'status': 'group_accepted',
        }
    self.request = request_logic.updateOrCreateFromFields(request_properties)

    # Create another user for second org admin who will be the backup admin
    email = '*****@*****.**'
    account = users.User(email=email)
    link_id = 'another_oa_user'
    name = 'Another Org Admin User'
    oa_user_properties = {
        'account': account,
        'link_id': link_id,
        'name': name,
        'agreed_to_tos': True,
        }
    self.another_oa_user = user_logic.updateOrCreateFromFields(
        oa_user_properties)

    request_properties = {
        'role': 'gsoc_org_admin',
        'user': self.another_oa_user,
        'group': self.org,
        'message': 'An Invitation Request Message',
        'status': 'group_accepted',
        }
    self.another_request = request_logic.updateOrCreateFromFields(
        request_properties)

    # Create a user for third org admin
    email = '*****@*****.**'
    account = users.User(email=email)
    link_id = 'third_oa_user'
    name = 'Third Org Admin User'
    oa_user_properties = {
        'account': account,
        'link_id': link_id,
        'name': name,
        'agreed_to_tos': True,
        }
    self.third_oa_user = user_logic.updateOrCreateFromFields(
        oa_user_properties)

    request_properties = {
        'role': 'gsoc_org_admin',
        'user': self.third_oa_user,
        'group': self.org,
        'message': 'An Invitation Request Message',
        'status': 'group_accepted',
        }
    self.third_request = request_logic.updateOrCreateFromFields(
        request_properties)
Exemplo n.º 8
0
  def createOrgAdminUserForAnotherOrg(self, with_oa_entity=False):
    """Create another organization, user and invitation for the user
    """

    # Create a user for org admin who is also the founder of the another_org
    email = '*****@*****.**'
    account = users.User(email=email)
    link_id = 'another_org_oa_user'
    name = 'Another Org Org Admin User'
    oa_user_properties = {
        'account': account,
        'link_id': link_id,
        'name': name,
        'agreed_to_tos': True,
        }
    self.another_org_oa_user = user_logic.updateOrCreateFromFields(
        oa_user_properties)

    # create another org for the program
    org_properties = {
        'link_id': 'another_org',
        'scope': self.program,
        'scope_path': self.program.key().id_or_name(),
        'name': 'Another Organization',
        'short_name': 'Another Org' ,
        'founder': self.another_org_oa_user,
        'home_page': 'http://anotherorg.com',
        'email': '*****@*****.**',
        'description': 'Another Organization Description',
        'contact_street': 'Another Organization Street',
        'contact_city': 'Another Organization City',
        'contact_country': 'Sweden',
        'contact_postalcode': '5653276 NG',
        'phone': '61-434-BLUE',
        'status': 'active',
        }
    self.another_org = org_logic.updateOrCreateFromFields(org_properties)

    request_properties = {
        'role': 'gsoc_org_admin',
        'user': self.another_org_oa_user,
        'group': self.another_org,
        'message': 'An Invitation Request Message',
        'status': 'group_accepted',
        }
    self.another_org_request = request_logic.updateOrCreateFromFields(
        request_properties)

    if with_oa_entity:
      # create a second org admin role for the second org admin user
      oa_properties = {
          'link_id': 'another_org_org_admin',
          'scope_path': self.another_org.key().id_or_name(),
          'scope': self.another_org,
          'program': self.program,
          'user' : self.another_org_oa_user,
          'given_name': 'AnotherOrgOrgAdmin',
          'surname': 'AnotherOrgAdministrator',
          'name_on_documents': 'AnotherOrgOrgAdmin Administrator',
          'birth_date': datetime.date(1975, 12, 15),
          'email': '*****@*****.**',
          'res_street': 'Another Org Admin Street',
          'res_city': 'Another Org Admin City',
          'res_state': 'Another Org Admin State',
          'res_country': 'Netherlands',
          'res_postalcode': '572461',
          'phone': '72-534-COLORLESS',
          'agreed_to_tos': True,
          }
      # create the org_admin_entity
      self.another_org_oa = gsoc_oa_logic.updateOrCreateFromFields(
        oa_properties)

      # Create an user for second org admin for another org
      email = '*****@*****.**'
      account = users.User(email=email)
      link_id = 'another_org_another_oa_user'
      name = 'Another Org Admin User'
      oa_user_properties = {
          'account': account,
          'link_id': link_id,
          'name': name,
          'agreed_to_tos': True,
          }
      self.another_org_oa_user = user_logic.updateOrCreateFromFields(
          oa_user_properties)

      request_properties = {
          'role': 'gsoc_org_admin',
          'user': self.another_org_oa_user,
          'group': self.another_org,
          'message': 'An Invitation Request Message',
          'status': 'group_accepted',
          }
      self.another_org_second_request = request_logic.updateOrCreateFromFields(
          request_properties)
Exemplo n.º 9
0
    def setUp(self):
        """Set up required for the view tests.
    """

        # Create a user for sponsor
        email = "*****@*****.**"
        account = users.User(email=email)
        link_id = 'a_sponsor_user'
        name = 'A Sponsor User'
        sponsor_user_properties = {
            'account': account,
            'link_id': link_id,
            'name': name,
        }
        self.sponsor_user = user_logic.updateOrCreateFromFields(
            sponsor_user_properties)

        # Create sponsor role for a_sponsor_user
        link_id = 'a_sponsor'
        name = link_id
        phone = '01234567'
        contact_postalcode = 'A postalcode'
        description = 'A description'
        contact_country = 'United States'
        short_name = 'AS'
        contact_city = 'A city'
        home_page = 'http://www.asponsor.com'
        email = '*****@*****.**'
        sponsor_properties = {
            'link_id': link_id,
            'name': name,
            'short_name': short_name,
            'founder': self.sponsor_user,
            'phone': phone,
            'description': description,
            'contact_country': contact_country,
            'contact_city': contact_city,
            'contact_street': 'A Street',
            'contact_postalcode': contact_postalcode,
            'home_page': home_page,
            'email': email,
        }
        self.sponsor = sponsor_logic.updateOrCreateFromFields(
            sponsor_properties)

        # Create a timeline for a program
        timeline_properties = {
            'link_id': 'a_program',
            'scope_path': 'a_sponsor',
            'scope': self.sponsor,
        }
        self.timeline = timeline_logic.updateOrCreateFromFields(
            timeline_properties)

        # Create a program for a_sponsor
        program_properties = {
            'link_id': 'a_program',
            'scope': self.sponsor,
            'scope_path': self.sponsor.key().id_or_name(),
            'name': 'A Program 2010',
            'short_name': 'AP2010',
            'group_label': 'AP',
            'description': 'This is the program for AP2010.',
            'apps_tasks_limit': 42,
            'slots': 42,
            'timeline': self.timeline,
            'status': 'visible',
        }
        self.program = program_logic.updateOrCreateFromFields(
            program_properties)

        # Create another user for org admin who is also the founder of the org
        email = '*****@*****.**'
        account = users.User(email=email)
        link_id = 'an_oa_user'
        name = 'An Org Admin User'
        oa_user_properties = {
            'account': account,
            'link_id': link_id,
            'name': name,
            'agreed_to_tos': True,
        }
        self.oa_user = user_logic.updateOrCreateFromFields(oa_user_properties)

        # create an org for the program
        org_properties = {
            'link_id': 'an_org',
            'scope': self.program,
            'scope_path': self.program.key().id_or_name(),
            'name': 'An Organization',
            'short_name': 'An Org',
            'founder': self.oa_user,
            'home_page': 'http://anorg.com',
            'email': '*****@*****.**',
            'description': 'An Organization Description',
            'contact_street': 'An Organization Street',
            'contact_city': 'An Organization City',
            'contact_country': 'United Kingdom',
            'contact_postalcode': '0123456 AnO',
            'phone': '1-555-BANANA',
            'status': 'active',
        }
        self.org = org_logic.updateOrCreateFromFields(org_properties)

        request_properties = {
            'role': 'gsoc_org_admin',
            'user': self.oa_user,
            'group': self.org,
            'message': 'An Invitation Request Message',
            'status': 'group_accepted',
        }
        self.request = request_logic.updateOrCreateFromFields(
            request_properties)

        # Create another user for second org admin who will be the backup admin
        email = '*****@*****.**'
        account = users.User(email=email)
        link_id = 'another_oa_user'
        name = 'Another Org Admin User'
        oa_user_properties = {
            'account': account,
            'link_id': link_id,
            'name': name,
            'agreed_to_tos': True,
        }
        self.another_oa_user = user_logic.updateOrCreateFromFields(
            oa_user_properties)

        request_properties = {
            'role': 'gsoc_org_admin',
            'user': self.another_oa_user,
            'group': self.org,
            'message': 'An Invitation Request Message',
            'status': 'group_accepted',
        }
        self.another_request = request_logic.updateOrCreateFromFields(
            request_properties)

        # Create a user for third org admin
        email = '*****@*****.**'
        account = users.User(email=email)
        link_id = 'third_oa_user'
        name = 'Third Org Admin User'
        oa_user_properties = {
            'account': account,
            'link_id': link_id,
            'name': name,
            'agreed_to_tos': True,
        }
        self.third_oa_user = user_logic.updateOrCreateFromFields(
            oa_user_properties)

        request_properties = {
            'role': 'gsoc_org_admin',
            'user': self.third_oa_user,
            'group': self.org,
            'message': 'An Invitation Request Message',
            'status': 'group_accepted',
        }
        self.third_request = request_logic.updateOrCreateFromFields(
            request_properties)
Exemplo n.º 10
0
    def createOrgAdminUserForAnotherOrg(self, with_oa_entity=False):
        """Create another organization, user and invitation for the user
    """

        # Create a user for org admin who is also the founder of the another_org
        email = '*****@*****.**'
        account = users.User(email=email)
        link_id = 'another_org_oa_user'
        name = 'Another Org Org Admin User'
        oa_user_properties = {
            'account': account,
            'link_id': link_id,
            'name': name,
            'agreed_to_tos': True,
        }
        self.another_org_oa_user = user_logic.updateOrCreateFromFields(
            oa_user_properties)

        # create another org for the program
        org_properties = {
            'link_id': 'another_org',
            'scope': self.program,
            'scope_path': self.program.key().id_or_name(),
            'name': 'Another Organization',
            'short_name': 'Another Org',
            'founder': self.another_org_oa_user,
            'home_page': 'http://anotherorg.com',
            'email': '*****@*****.**',
            'description': 'Another Organization Description',
            'contact_street': 'Another Organization Street',
            'contact_city': 'Another Organization City',
            'contact_country': 'Sweden',
            'contact_postalcode': '5653276 NG',
            'phone': '61-434-BLUE',
            'status': 'active',
        }
        self.another_org = org_logic.updateOrCreateFromFields(org_properties)

        request_properties = {
            'role': 'gsoc_org_admin',
            'user': self.another_org_oa_user,
            'group': self.another_org,
            'message': 'An Invitation Request Message',
            'status': 'group_accepted',
        }
        self.another_org_request = request_logic.updateOrCreateFromFields(
            request_properties)

        if with_oa_entity:
            # create a second org admin role for the second org admin user
            oa_properties = {
                'link_id': 'another_org_org_admin',
                'scope_path': self.another_org.key().id_or_name(),
                'scope': self.another_org,
                'program': self.program,
                'user': self.another_org_oa_user,
                'given_name': 'AnotherOrgOrgAdmin',
                'surname': 'AnotherOrgAdministrator',
                'name_on_documents': 'AnotherOrgOrgAdmin Administrator',
                'birth_date': datetime.date(1975, 12, 15),
                'email': '*****@*****.**',
                'res_street': 'Another Org Admin Street',
                'res_city': 'Another Org Admin City',
                'res_state': 'Another Org Admin State',
                'res_country': 'Netherlands',
                'res_postalcode': '572461',
                'phone': '72-534-COLORLESS',
                'agreed_to_tos': True,
            }
            # create the org_admin_entity
            self.another_org_oa = gsoc_oa_logic.updateOrCreateFromFields(
                oa_properties)

            # Create an user for second org admin for another org
            email = '*****@*****.**'
            account = users.User(email=email)
            link_id = 'another_org_another_oa_user'
            name = 'Another Org Admin User'
            oa_user_properties = {
                'account': account,
                'link_id': link_id,
                'name': name,
                'agreed_to_tos': True,
            }
            self.another_org_oa_user = user_logic.updateOrCreateFromFields(
                oa_user_properties)

            request_properties = {
                'role': 'gsoc_org_admin',
                'user': self.another_org_oa_user,
                'group': self.another_org,
                'message': 'An Invitation Request Message',
                'status': 'group_accepted',
            }
            self.another_org_second_request = request_logic.updateOrCreateFromFields(
                request_properties)