> ## Documentation Index
> Fetch the complete documentation index at: https://docs.base44.com/llms.txt
> Use this file to discover all available pages before exploring further.

# אבטחה

> שלוט בגישה לנתוני ה-entity שלך עם כללי אבטחה ברמת השורה וברמת השדה.

<div className="dev-docs-banner">
  <div className="dev-docs-banner-content">
    <div className="dev-docs-banner-title">
      אתה צופה בתיעוד למפתחים
    </div>

    <div className="dev-docs-banner-text">
      תיעוד זה מיועד למפתחים העובדים עם פלטפורמת המפתחים של Base44. למידע על ניהול נתוני האפליקציה באמצעות עורך האפליקציות, ראה <a href="/Building-your-app/Managing-your-app-data">ניהול נתוני אפליקציה</a>.
    </div>
  </div>
</div>

Entities תומכים בשתי רמות אבטחה:

* **Row Level Security (RLS)**: שולט באילו רשומות משתמשים יכולים לגשת.
* **Field Level Security (FLS)**: שולט באילו שדות בתוך רשומות משתמשים יכולים לגשת.

## סוגי הרשאה

לכל רמת אבטחה יש הרשאות שונות שניתן להגדיר. עבור כל הרשאה, אתה מגדיר מי מורשה לבצע את הפעולה.

### Row Level Security (RLS)

* `create` - הוסף רשומות חדשות
* `read` - צפה ברשומות
* `update` - שנה רשומות
* `delete` - הסר רשומות

### Field Level Security (FLS)

* `read` - צפה בשדה
* `write` - צור או שנה את השדה

## ערכי הרשאה

כל הרשאה מקבלת אחד מהערכים הבאים:

* `true` - אפשר לכל המשתמשים
* `false` - חסום את כל המשתמשים
* `{<condition>}` - אפשר למשתמשים שתואמים את התנאי

### תחביר תנאי

בעת שימוש ב-`{<condition>}` כערך הרשאה, אתה יכול להגדיר כללים שבודקים מאפייני משתמש או תפקידים.

**1. השוואה בין entity למשתמש**

השווה שדות רשומה לערכי המשתמש הנוכחי.

שדות entity שאתה יכול להפנות אליהם:

* `created_by` - אימייל של המשתמש שיצר את הרשומה
* `created_by_id` - מזהה המשתמש שיצר את הרשומה
* `entity_name` - שם סוג ה-entity
* `app_id` - App ID
* `environment` - או `prod` או `dev`
* `is_sample` - האם זה נתוני sample
* `is_deleted` - דגל soft delete
* `deleted_date` - מתי זה נמחק
* `data.*` - כל שדה מהמאפיינים של ה-entity schema שלך

משתני תבנית עבור ערכי משתמש:

* `{{user.email}}` - האימייל של המשתמש
* `{{user.id}}` - מזהה המשתמש
* `{{user.role}}` - תפקיד המשתמש
* `{{user.data.*}}` - שדות משתמש נוספים שאתה מגדיר

דוגמה:

```json theme={null}
{"created_by": "{{user.email}}"}
{"data.department": "{{user.data.department}}"}
{"data.status": "approved"}
```

**2. בדיקת תנאי משתמש**

בדוק מאפייני משתמש ישירות באמצעות `user_condition`.

שדות משתמש שאתה יכול לבדוק:

* `email` - האימייל של המשתמש
* `id` - מזהה המשתמש
* `role` - תפקיד המשתמש
* `data.*` - שדות משתמש מותאמים

דוגמה:

```json theme={null}
{"user_condition": {"role": "admin"}}
{"user_condition": {"data.level": "senior"}}
```

**3. תנאים מורכבים**

שלב מספר תנאים באמצעות אופרטורים.

אופרטורים נתמכים: `$or`, `$and`, `$nor`, `$in`, `$nin`, `$all`

דוגמה:

```json theme={null}
{
  "$or": [
    {"created_by": "{{user.email}}"},
    {"user_condition": {"role": "admin"}}
  ]
}
```

## דוגמת Row Level Security (RLS)

הוסף `rls` ברמת ה-entity:

```json theme={null}
{
  "name": "task",
  "type": "object",
  "properties": {...},
  "rls": {
    "create": true,
    "read": {"created_by": "{{user.email}}"},
    "update": {"created_by": "{{user.email}}"},
    "delete": {"user_condition": {"role": "admin"}}
  }
}
```

## דוגמת Field Level Security (FLS)

הוסף `rls` למאפייני שדה בודדים:

```json theme={null}
{
  "properties": {
    "salary": {
      "type": "number",
      "rls": {
        "read": {"user_condition": {"role": "admin"}},
        "write": {"user_condition": {"role": "admin"}}
      }
    }
  }
}
```

## דוגמה מלאה עם אבטחה

הנה entity schema עם RLS ו-FLS:

```json theme={null}
{
  "name": "Task",
  "type": "object",
  "title": "Task",
  "description": "A task item with priority, due date, and completion status",
  "properties": {
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    },
    "description": {
      "type": "string",
      "maxLength": 1000
    },
    "priority": {
      "type": "string",
      "enum": ["low", "medium", "high"],
      "default": "medium"
    },
    "completed": {
      "type": "boolean",
      "default": false
    },
    "due_date": {
      "type": "string",
      "format": "date"
    },
    "tags": {
      "type": "array",
      "items": {"type": "string"}
    },
    "internal_notes": {
      "type": "string",
      "rls": {
        "read": {"user_condition": {"role": "admin"}},
        "write": {"user_condition": {"role": "admin"}}
      }
    }
  },
  "required": ["title"],
  "rls": {
    "create": true,
    "read": {"created_by": "{{user.email}}"},
    "update": {"created_by": "{{user.email}}"},
    "delete": {"created_by": "{{user.email}}"}
  }
}
```

## פריסת כללי אבטחה

כללי אבטחה הם חלק מה-entity schema שלך. לאחר הוספה או עדכון של כללי אבטחה, פרוס באמצעות [`entities push`](/developers/references/cli/commands/entities-push). כללי אבטחה גם נפרסים אוטומטית כאשר אתה מריץ את פקודת [`deploy`](/developers/references/cli/commands/deploy) כדי לפרוס את כל הפרויקט שלך.

## ראה גם

* [Entities Overview](/developers/backend/resources/entities/overview): למד על תצורת schema של מסד הנתונים
* [Entity Schemas](/developers/backend/resources/entities/entity-schemas): הגדר את מבנה ה-entity שלך
* [User Schema](/developers/backend/resources/entities/user-schema): entity מובנה מיוחד לאימות משתמשים
* [Project Structure](/developers/backend/overview/project-structure): כיצד entity schemas משתלבים בפרויקט שלך

<Note>דף זה תורגם באמצעות בינה מלאכותית. למידע המדויק והעדכני ביותר, עיין ב[גרסה האנגלית](/). </Note>
