Skip to content

Commit

Permalink
Resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
JhumanJ committed Oct 13, 2023
2 parents cc618bb + f0939f3 commit e2c21ee
Show file tree
Hide file tree
Showing 51 changed files with 1,827 additions and 484 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ jobs:

- name: Build client
run: npm run build
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}

- name: Deploy to production
run: php vendor/bin/vapor deploy production --commit="${GITHUB_SHA}" --message="${GITHUB_REF}"
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/Forms/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function index($workspaceId)
$forms = $workspace->forms()->with(['creator','views','submissions'])
->orderByDesc('updated_at')
->paginate(10)->through(function (Form $form) use ($workspace, $workspaceIsPro){

// Add attributes for faster loading
$form->extra = (object) [
'loadedWorkspace' => $workspace,
Expand Down Expand Up @@ -113,7 +113,7 @@ public function update(UpdateFormRequest $request, string $id)
->processRequest($request)
->simulateCleaning($form->workspace)
->getData();

// Set Removed Properties
$formData['removed_properties'] = array_merge($form->removed_properties, collect($form->properties)->filter(function ($field) use ($formData) {
return (!Str::of($field['type'])->startsWith('nf-') && !in_array($field['id'], collect($formData['properties'])->pluck("id")->toArray()));
Expand Down
3 changes: 0 additions & 3 deletions app/Http/Controllers/SubscriptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ class SubscriptionController extends Controller
const SUBSCRIPTION_PLANS = ['monthly', 'yearly'];

const PRO_SUBSCRIPTION_NAME = 'default';
const ENTERPRISE_SUBSCRIPTION_NAME = 'enterprise';

const SUBSCRIPTION_NAMES = [
self::PRO_SUBSCRIPTION_NAME,
self::ENTERPRISE_SUBSCRIPTION_NAME
];

/**
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/AiGenerateFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AiGenerateFormRequest extends FormRequest
public function rules()
{
return [
'form_prompt' => 'required|string'
'form_prompt' => 'required|string|max:1000'
];
}
}
14 changes: 9 additions & 5 deletions app/Http/Requests/AnswerFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,14 @@ private function getSelectPropertyOptions($property): array

protected function prepareForValidation()
{
// Escape all '\' in select options
$receivedData = $this->toArray();
$mergeData = [];
collect($this->form->properties)->filter(function ($property) {
return in_array($property['type'], ['select', 'multi_select']);
})->each(function ($property) use ($receivedData, &$mergeData) {
$countryCodeMapper = json_decode(file_get_contents(resource_path('data/country_code_mapper.json')), true);
collect($this->form->properties)->each(function ($property) use ($countryCodeMapper, $receivedData, &$mergeData) {
$receivedValue = $receivedData[$property['id']] ?? null;
if (!is_null($receivedValue)) {

// Escape all '\' in select options
if(in_array($property['type'], ['select', 'multi_select']) && !is_null($receivedValue)){
if (is_array($receivedValue)) {
$mergeData[$property['id']] = collect($receivedValue)->map(function ($value) {
$value = Str::of($value);
Expand All @@ -244,6 +244,10 @@ protected function prepareForValidation()
)->toString();
}
}

if($property['type'] === 'phone_number' && (!isset($property['use_simple_text_input']) || !$property['use_simple_text_input']) && $receivedValue && in_array($receivedValue, $countryCodeMapper)){
$mergeData[$property['id']] = null;
}
});

$this->merge($mergeData);
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/UserFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function rules()
'editable_submissions' => 'boolean|nullable',
'editable_submissions_button_text' => 'string|min:1|max:50',
'confetti_on_submission' => 'boolean',
'auto_save'=> 'boolean',

// Properties
'properties' => 'required|array',
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Form/GenerateAiForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function handle()
} catch (\Exception $e) {
$this->completion->update([
'status' => AiFormCompletion::STATUS_FAILED,
'result' => $e->getMessage()
'result' => ['error' => $e->getMessage()]
]);
}

Expand Down
5 changes: 5 additions & 0 deletions app/Jobs/Form/StoreFormSubmissionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ private function getFormData()
if($this->form->is_pro && $field['type'] == 'signature') {
$finalData[$field['id']] = $this->storeSignature($answerValue);
}

// For Phone
if($field['type'] == 'phone_number' && $answerValue && ctype_alpha(substr($answerValue, 0, 2)) && (!isset($field['use_simple_text_input']) || !$field['use_simple_text_input'])) {
$finalData[$field['id']] = substr($answerValue, 2);
}
}

return $finalData;
Expand Down
10 changes: 10 additions & 0 deletions app/Models/Forms/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Spatie\Sluggable\SlugOptions;
use Stevebauman\Purify\Facades\Purify;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Casts\Attribute;

class Form extends Model
{
Expand Down Expand Up @@ -81,6 +82,7 @@ class Form extends Model
'editable_submissions',
'editable_submissions_button_text',
'confetti_on_submission',
'auto_save',

// Security & Privacy
'can_be_indexed',
Expand Down Expand Up @@ -217,6 +219,14 @@ public function getHasPasswordAttribute()
return !empty($this->password);
}

protected function removedProperties(): Attribute {
return Attribute::make(
get: function ($value) {
return $value ? json_decode($value, true) : [];
}
);
}

/**
* Relationships
*/
Expand Down
15 changes: 4 additions & 11 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Notifications\Notifiable;
use Laravel\Cashier\Billable;
use Tymon\JWTAuth\Contracts\JWTSubject;

class User extends Authenticatable implements JWTSubject //, MustVerifyEmail
class User extends Authenticatable implements JWTSubject
{
use Notifiable, HasFactory, Billable;

Expand Down Expand Up @@ -82,12 +80,7 @@ public function getHasFormsAttribute()

public function getIsSubscribedAttribute()
{
return $this->subscribed() || $this->subscribed(SubscriptionController::ENTERPRISE_SUBSCRIPTION_NAME);
}

public function getHasEnterpriseSubscriptionAttribute()
{
return $this->subscribed(SubscriptionController::ENTERPRISE_SUBSCRIPTION_NAME);
return $this->subscribed() || in_array($this->email, config('opnform.extra_pro_users_emails'));
}

public function getHasCustomerIdAttribute()
Expand All @@ -97,12 +90,12 @@ public function getHasCustomerIdAttribute()

public function getAdminAttribute()
{
return in_array($this->email, config('services.admin_emails'));
return in_array($this->email, config('opnform.admin_emails'));
}

public function getTemplateEditorAttribute()
{
return $this->admin || in_array($this->email, config('services.template_editor_emails'));
return $this->admin || in_array($this->email, config('opnform.template_editor_emails'));
}

/**
Expand Down
25 changes: 20 additions & 5 deletions app/Rules/ValidPhoneInputRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,37 @@

class ValidPhoneInputRule implements Rule
{

public ?int $reason = 0;

public function passes($attribute, $value)
{
if (!is_string($value) || !Str::startsWith($value, '+')) {
if (!is_string($value) || !$value) {
return false;
}

try {
if(ctype_alpha(substr($value, 0, 2))){ // First 2 will be country code
$value = substr($value, 2);
}
$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();
return $phoneUtil->isValidNumber($phoneUtil->parse($value));
$phone = $phoneUtil->parse($value);
$this->reason = $phoneUtil->isPossibleNumberWithReason($phone);
return $this->reason === \libphonenumber\ValidationResult::IS_POSSIBLE;
} catch (\Exception $e) {
return false;
}
}

public function message()
{
return 'The :attribute is invalid.';
return match ($this->reason) {
\libphonenumber\ValidationResult::IS_POSSIBLE => 'The :attribute is not valid for an unknown reason.',
\libphonenumber\ValidationResult::INVALID_COUNTRY_CODE => 'The :attribute does not have a valid country code.',
\libphonenumber\ValidationResult::TOO_SHORT => 'The :attribute is too short.',
\libphonenumber\ValidationResult::TOO_LONG => 'The :attribute is too long.',
\libphonenumber\ValidationResult::IS_POSSIBLE_LOCAL_ONLY => 'The :attribute is not a valid phone number (local number).',
\libphonenumber\ValidationResult::INVALID_LENGTH => 'The :attribute does not have a valid length.',
default => 'The :attribute is not a valid phone number.',
};
}
}
}
Loading

0 comments on commit e2c21ee

Please sign in to comment.