Skip to content

Commit

Permalink
Coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
akirk committed Nov 29, 2016
1 parent 4afda8c commit 5253a68
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
5 changes: 3 additions & 2 deletions gp-includes/routes/translation.php
Expand Up @@ -274,10 +274,11 @@ public function translations_post( $project_path, $locale_slug, $translation_set

$data['status'] = 'waiting';

if ( $this->can( 'approve', 'translation-set', $translation_set->id ) || $this->can( 'write', 'project', $project->id ) )
if ( $this->can( 'approve', 'translation-set', $translation_set->id ) || $this->can( 'write', 'project', $project->id ) ) {
$set_status = 'current';
else
} else {
$set_status = 'waiting';
}

$original = GP::$original->get( $original_id );
$data['warnings'] = GP::$translation_warnings->check( $original->singular, $original->plural, $translations, $locale );
Expand Down
17 changes: 14 additions & 3 deletions gp-includes/things/translation.php
Expand Up @@ -558,12 +558,18 @@ public function reject() {
$this->set_status( 'rejected' );
}

public function can_set_status( $status ) {
if ( 'rejected' === $status && get_current_user_id() == $this->user_id ) {
/**
* Decides whether the status of a translation can be changed to $desired_status.
*
* @param string $desired_status The desired status.
* @return bool Whether the status can be set.
*/
public function can_set_status( $desired_status ) {
if ( 'rejected' === $desired_status && get_current_user_id() === intval( $this->user_id ) ) {
return true;
}

if ( 'current' === $status || 'rejected' === $status ) {
if ( 'current' === $desired_status || 'rejected' === $desired_status ) {
if ( ! GP::$permission->current_user_can( 'approve', 'translation', $this->id, array( 'translation' => $this ) ) ) {
return false;
}
Expand All @@ -572,6 +578,11 @@ public function can_set_status( $status ) {
return true;
}

/**
* Changes the status of a translation if possible.
*
* @param string $status The status to be set.
*/
public function set_status( $status ) {
if ( ! $this->can_set_status( $status ) ) {
return false;
Expand Down

0 comments on commit 5253a68

Please sign in to comment.