Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New project landing page button #88

Merged
merged 8 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy to Secondary Staging Server
name: Deploy to Secondary Staging Server (ECAS Installation)

on:
workflow_dispatch:
Expand Down
137 changes: 137 additions & 0 deletions .github/workflows/deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Deploy to Staging Server (SciFY Installation - "Together")

on:
workflow_dispatch:
push:
branches:
- staging_scify_org

env:
PHP_VERSION: '8.2'
SERVER_HOSTNAME: 'staging.scify.org'
REMOTE_USER: 'project_crowdsourcing'
PROJECT_URL: 'crowdsourcing.scify.org'

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/[email protected]

- name: Install wireguard
run: sudo apt install wireguard

- name: Create wg0 file
uses: cuchi/[email protected]
with:
template: .github/templates/wg0.j2
output_file: wg0.conf
variables: |
WIREGUARD_PRIVATE_KEY=${{ secrets.WIREGUARD_PRIVATE_KEY }}
VPN_SERVER_PUBLIC_KEY=${{ secrets.VPN_SERVER_PUBLIC_KEY }}



- name: Move wg0.conf to /etc/wireguard
run: sudo mv wg0.conf /etc/wireguard/wg0.conf

- name: Start wireguard
run: sudo wg-quick up wg0

- name: Checkout repo
uses: actions/[email protected]

- name: Add frodo to etc hosts
run: echo "10.10.0.100 frodo.scify.org" | sudo tee -a /etc/hosts

- name: read password from vault
uses: hashicorp/vault-action@v2
with:
url: https://frodo.scify.org:8200
caCertificate: ${{ secrets.VAULT_CA_CERT }}
method: userpass
username: ${{ secrets.VAULT_USER }}
password: ${{ secrets.VAULT_PASSWORD }}
secrets: |
Projects/data/crowdsourcing/scify-installation-together/staging/database db_name | DB_NAME ;
Projects/data/crowdsourcing/scify-installation-together/staging/database db_user | DB_USER ;
Projects/data/crowdsourcing/scify-installation-together/staging/database password | DB_PASSWORD ;
Projects/data/crowdsourcing/staging_sec_data/google_client_secrets google_client_id | GOOGLE_CLIENT_ID ;
Projects/data/crowdsourcing/production/email/laravel_mailgun_env_variables MAILGUN_SECRET | MAILGUN_SECRET ;





- name: Create .env file
uses: cuchi/[email protected]
with:
template: .github/templates/.env.j2
output_file: .env
variables: |
DB_NAME=${{ env.DB_NAME }}
DB_USER=${{ env.DB_USER }}
DB_PASSWORD=${{ env.DB_PASSWORD }}
LARAVEL_STAGING_SCIFY_APP_KEY=${{ secrets.LARAVEL_STAGING_SCIFY_APP_KEY }}
PROJECT_URL=${{ env.PROJECT_URL }}
MAILGUN_SECRET=${{ env.MAILGUN_SECRET }}
PERSONAL_CLIENT_ID=${{ secrets.PERSONAL_CLIENT_ID }}
PERSONAL_CLIENT_SECRET=${{ secrets.PERSONAL_CLIENT_SECRET }}
PASSWORD_CLIENT_SECRET=${{ secrets.PASSWORD_CLIENT_SECRET }}
FACEBOOK_CLIENT_ID=${{ secrets.FACEBOOK_CLIENT_ID }}
FACEBOOK_CLIENT_SECRET=${{ secrets.FACEBOOK_CLIENT_SECRET }}
TWITTER_CLIENT_ID=${{ secrets.TWITTER_CLIENT_ID }}
TWITTER_CLIENT_SECRET=${{ secrets.TWITTER_CLIENT_SECRET }}
GOOGLE_CLIENT_ID=${{ env.GOOGLE_CLIENT_ID }}
GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}
MICROSOFT_CLIENT_ID=${{ secrets.MICROSOFT_CLIENT_ID }}
MICROSOFT_CLIENT_SECRET=${{ secrets.MICROSOFT_CLIENT_SECRET }}
LINKEDIN_CLIENT_ID=${{ secrets.LINKEDIN_CLIENT_ID }}
LINKEDIN_CLIENT_SECRET=${{ secrets.LINKEDIN_CLIENT_SECRET }}
DEFAULT_ADMIN_USER_PASSWORD_FOR_SEED=${{ secrets.DEFAULT_ADMIN_USER_PASSWORD_FOR_SEED }}
GOOGLE_TRANSLATE_KEY=${{ secrets.GOOGLE_TRANSLATE_KEY }}
MAILCHIMP_API_KEY=${{ secrets.MAILCHIMP_API_KEY }}
SENTRY_LARAVEL_DSN=${{ secrets.SENTRY_LARAVEL_DSN }}
API_AUTH_TOKEN=${{ secrets.API_AUTH_TOKEN }}
USERWAY_ID=${{ secrets.USERWAY_ID }}
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}



- name: Setup node
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Install node dependencies
run: npm install

- name: Build assets
run: npm run build


- name: SCP files to staging server
uses: easingthemes/[email protected]
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_KEY_STAGING_SERVER }}
REMOTE_PORT: 222
SOURCE: "./"
REMOTE_HOST: ${{ env.SERVER_HOSTNAME }}
REMOTE_USER: ${{ env.REMOTE_USER }}
TARGET: "/home/${{ env.REMOTE_USER }}/www/${{ env.PROJECT_URL }}"


- name: Run composer install on remote server
uses: appleboy/[email protected]
with:
host: ${{ env.SERVER_HOSTNAME }}
port: 222
username: ${{ env.REMOTE_USER }}
key: ${{ secrets.SSH_KEY_STAGING_SERVER }}
script: |
source /home/${{ env.REMOTE_USER }}/.profile
cd /home/${{ env.REMOTE_USER }}/www/${{ env.PROJECT_URL }}
composer install --no-interaction --no-progress --optimize-autoloader
# --no-dev
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ This is a [Laravel](https://laravel.com/) Web Application for Crowdsourcing Proj
- [Related HTML Template](#related-html-template)
- [PHP code style - Laravel Pint](#php-code-style---laravel-pint)
- [Installation-specific resources](#installation-specific-resources)
- [Development Guidelines](#development-guidelines)
- [Directory Structure](#directory-structure)
- [About the Repository Pattern](#about-the-repository-pattern)
- [Run Tests](#run-tests)
- [How to debug](#how-to-debug)
- [Troubleshooting](#troubleshooting)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Notifications\QuestionnaireResponded;
use App\Repository\CrowdSourcingProject\CrowdSourcingProjectRepository;
use App\Repository\CrowdSourcingProject\CrowdSourcingProjectStatusHistoryRepository;
use App\Repository\CrowdSourcingProject\Problem\CrowdSourcingProjectProblemRepository;
use App\Repository\LanguageRepository;
use App\Repository\Questionnaire\QuestionnaireRepository;
use App\Repository\Questionnaire\Responses\QuestionnaireResponseRepository;
Expand Down Expand Up @@ -41,6 +42,7 @@ class CrowdSourcingProjectManager {
protected CrowdSourcingProjectColorsManager $crowdSourcingProjectColorsManager;
protected QuestionnaireResponseRepository $questionnaireResponseRepository;
protected CrowdSourcingProjectTranslationManager $crowdSourcingProjectTranslationManager;
protected CrowdSourcingProjectProblemRepository $crowdSourcingProjectProblemRepository;

public function __construct(CrowdSourcingProjectRepository $crowdSourcingProjectRepository,
QuestionnaireRepository $questionnaireRepository,
Expand All @@ -51,7 +53,8 @@ public function __construct(CrowdSourcingProjectRepository $crowdSourcingProject
LanguageRepository $languageRepository,
CrowdSourcingProjectColorsManager $crowdSourcingProjectColorsManager,
QuestionnaireResponseRepository $questionnaireResponseRepository,
CrowdSourcingProjectTranslationManager $crowdSourcingProjectTranslationManager) {
CrowdSourcingProjectTranslationManager $crowdSourcingProjectTranslationManager,
CrowdSourcingProjectProblemRepository $crowdSourcingProjectProblemRepository) {
$this->crowdSourcingProjectRepository = $crowdSourcingProjectRepository;
$this->questionnaireRepository = $questionnaireRepository;
$this->crowdSourcingProjectStatusManager = $crowdSourcingProjectStatusManager;
Expand All @@ -62,6 +65,7 @@ public function __construct(CrowdSourcingProjectRepository $crowdSourcingProject
$this->crowdSourcingProjectColorsManager = $crowdSourcingProjectColorsManager;
$this->questionnaireResponseRepository = $questionnaireResponseRepository;
$this->crowdSourcingProjectTranslationManager = $crowdSourcingProjectTranslationManager;
$this->crowdSourcingProjectProblemRepository = $crowdSourcingProjectProblemRepository;
}

public function getCrowdSourcingProjectsForHomePage(): Collection {
Expand Down Expand Up @@ -94,15 +98,7 @@ public function getCrowdSourcingProjectBySlug($project_slug, $withRelationships
public function getCrowdSourcingProjectViewModelForLandingPage(
$questionnaireIdRequestedInTheURL,
$project_slug): CrowdSourcingProjectForLandingPage {
$userId = null;

// if the user is logged in, get the user id
if (Auth::check()) {
$userId = Auth::id();
} // else, check if the user is anonymous (by checking the cookie) and get the user id
elseif (isset($_COOKIE[UserManager::$USER_COOKIE_KEY]) && intval($_COOKIE[UserManager::$USER_COOKIE_KEY])) {
$userId = intval($_COOKIE[UserManager::$USER_COOKIE_KEY]);
}
$userId = Auth::id() ?? intval($_COOKIE[UserManager::$USER_COOKIE_KEY] ?? 0);

$project = $this->getCrowdSourcingProjectBySlug($project_slug);

Expand All @@ -122,6 +118,7 @@ public function getCrowdSourcingProjectViewModelForLandingPage(
$shareUrlForFacebook = '';
$shareUrlForTwitter = '';
$countAll = 0;
$projectHasPublishedProblems = false;
if ($questionnaire) {
$countAll = $this->questionnaireRepository->countAllResponsesForQuestionnaire($questionnaire->id);
$questionnaireGoalVM = $this->questionnaireGoalManager->getQuestionnaireGoalViewModel($questionnaire, $countAll);
Expand All @@ -131,6 +128,9 @@ public function getCrowdSourcingProjectViewModelForLandingPage(
$shareButtonsModel = new QuestionnaireSocialShareButtons($questionnaire, $idOfUserThatCanShareTheQuestionnaire);
$shareUrlForFacebook = $shareButtonsModel->getSocialShareURL($project, 'facebook');
$shareUrlForTwitter = $shareButtonsModel->getSocialShareURL($project, 'twitter');
} else {
// if there is no questionnaire, we need to check if this project has published problems
$projectHasPublishedProblems = $this->crowdSourcingProjectProblemRepository->projectHasPublishedProblems($project->id);
}
if ($feedbackQuestionnaire) {
$userFeedbackQuestionnaireResponse =
Expand All @@ -143,6 +143,7 @@ public function getCrowdSourcingProjectViewModelForLandingPage(
return new CrowdSourcingProjectForLandingPage($project,
$questionnaire,
$feedbackQuestionnaire,
$projectHasPublishedProblems,
$userResponse,
$userFeedbackQuestionnaireResponse,
$countAll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
namespace App\Models\CrowdSourcingProject\Problem;

use Awobaz\Compoships\Compoships;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;

class CrowdSourcingProjectProblem extends Model {
use Compoships;
use HasFactory, SoftDeletes;
use SoftDeletes;

protected $table = 'crowd_sourcing_project_problems';
protected $fillable = ['id', 'project_id', 'slug', 'status_id', 'img_url', 'default_language_id'];
Expand All @@ -22,6 +21,6 @@ public function defaultTranslation(): HasOne {
}

public function translations(): HasMany {
return $this->hasMany(CrowdSourcingProjectProblemTranslation::class, 'project_id', 'id');
return $this->hasMany(CrowdSourcingProjectProblemTranslation::class, 'problem_id', 'id');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
use App\Models\CompositeKeysModel;
use App\Models\Language;
use Awobaz\Compoships\Compoships;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class CrowdSourcingProjectProblemTranslation extends CompositeKeysModel {
use Compoships;
use HasFactory;

protected $table = 'crowd_sourcing_project_problem_translations';
protected $fillable = ['problem_id', 'language_id', 'title', 'description'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Repository\CrowdSourcingProject\Problem;

use App\BusinessLogicLayer\lkp\CrowdSourcingProjectProblemStatusLkp;
use App\Models\CrowdSourcingProject\CrowdSourcingProject;
use App\Models\CrowdSourcingProject\Problem\CrowdSourcingProjectProblem;
use App\Repository\Repository;
Expand All @@ -17,4 +18,13 @@ public function getModelClassName() {
public function getProjectWithProblemsByProjectSlug(string $project_slug): CrowdSourcingProject {
return CrowdSourcingProject::where('slug', $project_slug)->with(['problems'])->first();
}

public function projectHasPublishedProblems(int $project_id): bool {
$hasPublishedProblemsWithTranslations = CrowdSourcingProjectProblem::where('project_id', $project_id)
->where('status_id', CrowdSourcingProjectProblemStatusLkp::PUBLISHED)
->whereHas('translations')
->exists();

return $hasPublishedProblemsWithTranslations;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class CrowdSourcingProjectForLandingPage {
public $project;
public $questionnaire;
public $feedbackQuestionnaire;
public $projectHasPublishedProblems;
public $userResponse;
public $userFeedbackQuestionnaireResponse;
public $totalResponses;
Expand All @@ -24,6 +25,7 @@ public function __construct(
$project,
$questionnaire,
$feedbackQuestionnaire,
$projectHasPublishedProblems,
$userResponse,
$userFeedbackQuestionnaireResponse,
$totalResponses,
Expand All @@ -35,6 +37,7 @@ public function __construct(
$this->project = $project;
$this->questionnaire = $questionnaire;
$this->feedbackQuestionnaire = $feedbackQuestionnaire;
$this->projectHasPublishedProblems = $projectHasPublishedProblems;
$this->userResponse = $userResponse;
$this->userFeedbackQuestionnaireResponse = $userFeedbackQuestionnaireResponse;
$this->totalResponses = $totalResponses;
Expand Down
Loading
Loading