示例#1
0
 /**
  * Creates an account
  */
 private function create_account(array $ldapuser, array $tokens)
 {
     $user = null;
     $person = null;
     midgardmvc_core::get_instance()->authorization->enter_sudo('midgardmvc_core');
     $transaction = new midgard_transaction();
     $transaction->begin();
     $persons = $this->get_persons($ldapuser);
     if (count($persons) == 0) {
         $person = $this->create_person($ldapuser, $tokens);
     } else {
         // we have multiple persons with the same firstname and lastname
         // let's see the corresponding midgard_user object and its login field
         foreach ($persons as $person) {
             $user = com_meego_packages_utils::get_user_by_person_guid($person->guid);
             if ($user->login == $tokens['login']) {
                 break;
             } else {
                 $user = null;
                 $person = null;
             }
         }
     }
     if (!$user) {
         if (!$person) {
             $person = $this->create_person($ldapuser, $tokens);
         }
         if ($person) {
             $user = new midgard_user();
             $user->login = $tokens['login'];
             $user->password = '';
             $user->usertype = 1;
             $user->authtype = 'LDAP';
             $user->active = true;
             $user->set_person($person);
             if (!$user->create()) {
                 midgardmvc_core::get_instance()->log(__CLASS__, "Creating midgard_user for LDAP user failed: " . midgard_connection::get_instance()->get_error_string(), 'warning');
                 $transaction->rollback();
                 midgardmvc_core::get_instance()->authorization->leave_sudo();
                 return false;
             }
         }
     }
     midgardmvc_core::get_instance()->authorization->leave_sudo();
     if (!$transaction->commit()) {
         return false;
     }
     return true;
 }
示例#2
0
 public function post_delete(array $args)
 {
     $this->get_delete($args);
     if (isset($_POST['delete'])) {
         $transaction = new midgard_transaction();
         $transaction->begin();
         $this->object->delete();
         $transaction->commit();
         $this->mvc->log(__CLASS__, 'Comment with id: ' . $this->object->id . ' deleted', 'info');
         $this->mvc->cache->invalidate(array($this->object->guid));
         if (array_key_exists('relocate', $_GET)) {
             $this->mvc->head->relocate($_GET['relocate']);
         } else {
             $this->mvc->head->relocate($this->mvc->context->get_request()->get_prefix());
         }
     }
 }
示例#3
0
 private function create_account(array $ldapuser, array $tokens)
 {
     midgardmvc_core::get_instance()->authorization->enter_sudo('midgardmvc_core');
     $transaction = new midgard_transaction();
     $transaction->begin();
     $qb = new midgard_query_builder('midgard_person');
     $qb->add_constraint('firstname', '=', $ldapuser['firstname']);
     $qb->add_constraint('lastname', '=', $ldapuser['lastname']);
     $persons = $qb->execute();
     if (count($persons) == 0) {
         $person = new midgard_person();
         $person->firstname = $ldapuser['firstname'];
         $person->lastname = $ldapuser['lastname'];
         if (!$person->create()) {
             midgardmvc_core::get_instance()->log(__CLASS__, "Creating midgard_person for LDAP user failed: " . midgard_connection::get_instance()->get_error_string(), 'warning');
             $transaction->rollback();
             midgardmvc_core::get_instance()->authorization->leave_sudo();
             return false;
         }
     } else {
         $person = $persons[0];
     }
     $person->set_parameter('midgardmvc_core_services_authentication_ldap', 'employeenumber', $ldapuser['employeenumber']);
     $user = new midgard_user();
     $user->login = $tokens['login'];
     $user->password = '';
     $user->usertype = 1;
     $user->authtype = 'LDAP';
     $user->active = true;
     $user->set_person($person);
     if (!$user->create()) {
         midgardmvc_core::get_instance()->log(__CLASS__, "Creating midgard_user for LDAP user failed: " . midgard_connection::get_instance()->get_error_string(), 'warning');
         $transaction->rollback();
         midgardmvc_core::get_instance()->authorization->leave_sudo();
         return false;
     }
     if (!$transaction->commit()) {
         midgardmvc_core::get_instance()->authorization->leave_sudo();
         return false;
     }
     midgardmvc_core::get_instance()->authorization->leave_sudo();
     return true;
 }
示例#4
0
 public function post_delete(array $args)
 {
     $this->get_delete($args);
     if (isset($_POST['delete'])) {
         $transaction = new midgard_transaction();
         $transaction->begin();
         $this->object->delete();
         $transaction->commit();
         // FIXME: We can remove this once signals are used for this
         midgardmvc_core::get_instance()->cache->invalidate(array($this->object->guid));
         midgardmvc_core::get_instance()->head->relocate(midgardmvc_core::get_instance()->context->get_request()->get_prefix());
         // TODO: This needs a better redirect
     }
 }
示例#5
0
 /**
  * Creates a new device
  * But it makes sure that the name is unique
  */
 public function post_create(array $args)
 {
     $this->get_create($args);
     try {
         $transaction = new midgard_transaction();
         $transaction->begin();
         $this->process_form();
         // generate a unique name
         $this->object->name = com_meego_devprogram_utils::generate_unique_name($this->object);
         if (!$this->object->name) {
             throw new midgardmvc_exception('Could not generate a valid, unique name to a new object');
         }
         $res = $this->object->create();
         $transaction->commit();
         // TODO: add uimessage of $e->getMessage();
         $this->relocate_to_read();
     } catch (midgardmvc_helper_forms_exception_validation $e) {
         // TODO: UImessage
     } catch (midgardmvc_exception $e) {
         // TODO: UImessage
     }
 }
 private function create_account(fi_openkeidas_registration_user $user, $password)
 {
     if (!$this->check_email($user->email)) {
         midgardmvc_core::get_instance()->uimessages->add(array('title' => 'Käyttäjätunnus olemassa', 'message' => 'Antamallasi sähköpostiosoitteella on jo käyttäjätunnus. Ole hyvä ja kirjaudu sisään.', 'type' => 'ok'));
         midgardmvc_core::get_instance()->head->relocate('/mgd:login');
     }
     midgardmvc_core::get_instance()->authorization->enter_sudo('fi_openkeidas_registration');
     $transaction = new midgard_transaction();
     $transaction->begin();
     $method = 'create';
     if ($user->guid) {
         $method = 'update';
     }
     if (!$user->{$method}()) {
         $transaction->rollback();
         midgardmvc_core::get_instance()->authorization->leave_sudo();
         throw new midgardmvc_exception_httperror('Failed to create user');
     }
     // Typecast to midgard_person
     $person = new midgard_person($user->guid);
     $account = new midgard_user();
     $account->login = $user->email;
     $account->password = sha1($password);
     $account->usertype = 1;
     $account->authtype = 'SHA1';
     $account->active = true;
     $account->set_person($person);
     if (!$account->create()) {
         $transaction->rollback();
         midgardmvc_core::get_instance()->authorization->leave_sudo();
         throw new midgardmvc_exception_httperror('Failed to create user');
     }
     if (!$transaction->commit()) {
         $transaction->rollback();
         midgardmvc_core::get_instance()->authorization->leave_sudo();
         throw new midgardmvc_exception_httperror('Failed to create user');
     }
     midgardmvc_core::get_instance()->authorization->leave_sudo();
     return $account;
 }
示例#7
0
 public function post_update(array $args)
 {
     $this->get_update($args);
     $this->form->bmi->set_readonly(false);
     $this->form->process_post();
     $this->form->bmi->set_readonly(true);
     $transaction = new midgard_transaction();
     $transaction->begin();
     foreach ($this->data['stats'] as $name => $value) {
         if ($this->form->{$name}->get_value() == $value) {
             continue;
         }
         $stat = new fi_openkeidas_diary_stat();
         $stat->date = new midgard_datetime();
         $stat->person = midgardmvc_core::get_instance()->authentication->get_person()->id;
         $stat->stat = $name;
         $stat->value = $this->form->{$name}->get_value();
         $stat->create();
         $this->data['stats'][$name] = $this->form->{$name}->get_value();
     }
     $transaction->commit();
 }
示例#8
0
 /**
  * Creates a new provider
  * But it makes sure that the name is unique
  */
 public function post_create(array $args)
 {
     $this->get_create($args);
     $user = com_meego_devprogram_utils::get_current_user();
     try {
         $transaction = new midgard_transaction();
         $transaction->begin();
         $this->process_form();
         // generate a unique name
         $this->object->name = com_meego_devprogram_utils::generate_unique_name($this->object);
         if (!$this->object->name) {
             throw new midgardmvc_exception('Could not generate a valid, unique name to a new object');
         }
         $res = $this->object->create();
         if ($res) {
             // create the membership object
             $membership = new com_meego_devprogram_provider_membership();
             $membership->provider = $this->object->id;
             $membership->person = $user->person;
             $membership->status = CMD_MEMBERSHIP_APPROVED;
             $membership->reason = $this->mvc->i18n->get('label_provider_original_creator');
             $membership->create();
         }
         $transaction->commit();
         // TODO: add uimessage of $e->getMessage();
         $this->relocate_to_read();
     } catch (midgardmvc_helper_forms_exception_validation $e) {
         // TODO: UImessage
     } catch (midgardmvc_exception $e) {
         // TODO: UImessage
     }
 }
示例#9
0
<?php

$filepath = ini_get('midgard.configuration_file');
$config = new midgard_config();
$config->read_file_at_path($filepath);
$mgd = midgard_connection::get_instance();
$mgd->open_config($config);
$basedir = dirname(__FILE__) . '/../..';
require "{$basedir}/midgardmvc_core/framework.php";
$mvc = midgardmvc_core::get_instance("{$basedir}/application.yml");
array_walk(com_meego_planet_utils::get_items(null, 'com_meego_planet_item_with_score'), function ($item) {
    $score = $item->score;
    $score += com_meego_planet_calculate::age($item->metadata->published);
    if (round($item->agedscore, 2) != round($score, 2)) {
        // FIXME: This is here until we can get QuerySelect out of read-only state
        $item = new com_meego_planet_item_with_score($item->guid);
        $transaction = new midgard_transaction();
        $transaction->begin();
        echo "Updating age score of {$item->title} to {$score}\n";
        $item->agedscore = $score;
        $item->update();
        $transaction->commit();
    }
});
示例#10
0
 /**
  * Handles posts from application judges
  *
  * @param array args
  */
 public function post_judge(array $args)
 {
     $this->get_judge($args);
     try {
         $transaction = new midgard_transaction();
         $transaction->begin();
         $this->process_form();
         $this->object->update();
         $transaction->commit();
         // Redirect to application lists of that program
         $this->mvc->head->relocate($this->data['provider']->list_memberships_url);
     } catch (midgardmvc_helper_forms_exception_validation $e) {
         // TODO: UImessage
     }
 }
示例#11
0
 /**
  * Process a comment post
  */
 public function post_add(array $args)
 {
     $success = true;
     if (!$this->user) {
         // Voting requires authentication
         $auth = com_meego_ocs_utils::authenticate($args);
         if (!$auth) {
             return null;
         }
     }
     $ocs = new com_meego_ocs_OCSWriter();
     if (!isset($_POST['content'])) {
         $ocs->writeError('Content must not be empty', 101);
         $ocs->endDocument();
         self::output_xml($ocs);
         return;
     }
     if (!(isset($_POST['message']) || isset($_POST['subject']))) {
         $ocs->writeError('Message or subject must not be empty', 102);
         $ocs->endDocument();
         self::output_xml($ocs);
         return;
     }
     if ($_POST['type'] != '1' && $_POST['type'] != '8') {
         $ocs->writeError('Content type: ' . $_POST['type'] . ' is not supported.', 104);
         $ocs->endDocument();
         self::output_xml($ocs);
         return;
     }
     $package = new com_meego_package();
     $package->get_by_id((int) $_POST['content']);
     if (!$package->guid) {
         $success = false;
         $this->mvc->log(__CLASS__, 'Package with id: ' . $_POST['content'] . ' not found.', 'error');
     }
     if ($success) {
         switch ($_POST['type']) {
             case 1:
                 $message = 'Rating via OCS failed. Could not create rating object for package ' . $package->name . '(id: ' . $package->id . ').';
                 $comment = new com_meego_comments_comment();
                 if (isset($_POST['parent']) && !empty($_POST['parent'])) {
                     $parent = new com_meego_comments_comment();
                     $parent->get_by_id((int) $_POST['parent']);
                     if ($parent->to != $package->guid) {
                         $success = false;
                         $this->mvc->log(__CLASS__, $message . ' Parent comment is not related to the content item', 'error');
                     }
                     $comment->up = $parent->id;
                 }
                 $comment->to = $package->guid;
                 $comment->content = $_POST['message'];
                 if (isset($_POST['subject']) && !empty($_POST['subject'])) {
                     $comment->title = $_POST['subject'];
                 }
                 $comment->create();
                 if ($comment->guid) {
                     $rating = new com_meego_ratings_rating();
                     $rating->to = $package->guid;
                     // for comments we have no votes
                     $rating->rating = 0;
                     $rating->comment = $comment->id;
                     $success = $rating->create();
                     if ($success) {
                         $message = 'Rating via OCS finished. New rating object is: ' . $rating->guid . '.';
                     }
                 }
                 break;
             case 8:
                 $name = substr($_POST['message'], 0, strpos($_POST['message'], ':'));
                 $workflows = $this->mvc->configuration->workflows;
                 if (array_key_exists($name, $workflows)) {
                     if (is_object($package)) {
                         $this->mvc->component->load_library('Workflow');
                         $workflow_definition = new $workflows[$name]['provider']();
                         $values = $workflow_definition->start($package);
                         if (array_key_exists('execution', $values)) {
                             // get the db form and fill in the fields
                             $form = new midgardmvc_ui_forms_form($values['review_form']);
                             $transaction = new midgard_transaction();
                             $transaction->begin();
                             $instance = new midgardmvc_ui_forms_form_instance();
                             $instance->form = $form->id;
                             $instance->relatedobject = $package->guid;
                             $instance->create();
                             if (isset($instance->guid)) {
                                 // give values to the db fields taken from the posted values and store each of them
                                 // use the form instance ID as "form" property of the fields
                                 $posted_values = explode(',', substr($_POST['message'], strpos($_POST['message'], ':') + 1));
                                 $db_fields = midgardmvc_ui_forms_generator::list_fields($form);
                                 $i = 0;
                                 foreach ($db_fields as $dbfield) {
                                     if (!$success) {
                                         // if 1 field creation failed then end this loop as fast as possible
                                         continue;
                                     }
                                     switch ($dbfield->widget) {
                                         case 'checkbox':
                                             $holder = "booleanvalue";
                                             $value = $posted_values[$i];
                                             break;
                                         default:
                                             $options = explode(',', $dbfield->options);
                                             $value = $options[(int) $posted_values[$i]];
                                             $holder = "stringvalue";
                                     }
                                     $field_instance = new midgardmvc_ui_forms_form_instance_field();
                                     $field_instance->form = $instance->id;
                                     $field_instance->field = $dbfield->guid;
                                     $field_instance->{$holder} = $value;
                                     if (!$field_instance->create()) {
                                         $success = false;
                                     }
                                     ++$i;
                                 }
                                 if ($success) {
                                     $message = 'QA via OCS by user ' . $this->user->login . ' for package: ' . $package->name . ' (id: ' . $package->id . ')';
                                     try {
                                         $workflow = $workflow_definition->get();
                                         $execution = new midgardmvc_helper_workflow_execution_interactive($workflow, $values['execution']);
                                     } catch (ezcWorkflowExecutionException $e) {
                                         $success = false;
                                         $this->mvc->log(__CLASS__, $message . ' failed. Workflow: ' . $values['workflow'] . ' not found. See error: ' . $e->getMessage(), 'error');
                                     }
                                     if ($success) {
                                         $args = array('review' => $instance->guid);
                                         try {
                                             $values = $workflow_definition->resume($execution->guid, $args);
                                         } catch (ezcWorkflowInvalidInputException $e) {
                                             $success = false;
                                             $this->mvc->log(__CLASS__, $message . ' failed. Maybe a quick re-submit? See error: ' . $e->getMessage(), 'error');
                                         }
                                         $transaction->commit();
                                         $this->mvc->log(__CLASS__, 'New QA form guid: ' . $instance->guid, 'info');
                                     }
                                 }
                             }
                             if (!$success) {
                                 $this->mvc->log(__CLASS__, $message . ' failed. Probably a form instance or a field creation failed.', 'info');
                                 $transaction->rollback();
                             }
                         }
                     }
                 }
                 break;
         }
         if ($success) {
             // POST went fine
             $ocs->writeMeta(null, null, 'Posting succeded.', 'ok', 100);
             $this->mvc->log(__CLASS__, $message, 'info');
             // create activity object
             $created = null;
             switch ($_POST['type']) {
                 case 1:
                     $verb = 'comment';
                     $summary = 'The user commented an application via OCS.';
                     $creator = $rating->metadata->creator;
                     $created = $rating->metadata->created;
                     $target = $rating->to;
                     break;
                 case 8:
                     $verb = 'review';
                     $summary = 'The user reviewed an application via OCS.';
                     $creator = $instance->metadata->creator;
                     $created = $instance->metadata->created;
                     $target = $instance->relatedobject;
                     break;
             }
             if ($created) {
                 $res = midgardmvc_account_controllers_activity::create_activity($creator, $verb, $target, $summary, 'Apps', $created);
             }
             unset($created, $creator, $target);
         }
     }
     if (!$success) {
         $ocs->writeError('Comment posting (type: ' . $_POST['type'] . ') failed.');
         $this->mvc->log(__CLASS__, $message . ' failed.', 'info');
     }
     $ocs->endDocument();
     self::output_xml($ocs);
 }
示例#12
0
 /**
  * Creating a basecategory
  * @todo: finalize
  */
 public function post_create_basecategory(array $args)
 {
     $this->mvc->authorization->require_admin();
     $saved = true;
     // save categories update existing ones
     foreach ($_POST['categories'] as $category) {
         // look if basecategory with such name exists already
         $this->load_object(array('basecategory' => $category['name']));
         $this->object->description = $category['description'];
         if ($this->object->guid) {
             // update
             $this->object->update();
         } else {
             // create
             $this->object->name = $category['name'];
             $transaction = new midgard_transaction();
             $transaction->begin();
             $this->object->create();
             $transaction->commit();
             // @todo: try to do the mapping now
             // $this->post_create_relations(array('basecategory' => $this->object->guid));
         }
         if (!$this->object->guid) {
             $saved = false;
         }
     }
     if ($saved) {
         try {
             // @todo: add an uimessage
             $this->data['relocate'] = $this->get_url_admin_index();
             $this->mvc->head->relocate($this->data['relocate']);
         } catch (Exception $e) {
             // workaround for an MVC bug; this try - catch should not be needed
         }
     } else {
         throw new midgardmvc_exception_httperror("Could not populate default base categories", 500);
     }
 }