Fastapi Org Permission Module Skill logo

Fastapi Org Permission Module Skill

Community
jiushiwon
fastapi-org-permission-module-skill

Python FastAPI 组织权限模块技能。面向已有 FastAPI 项目的开发者,提供组织架构、部门管理、角色权限、RBAC、菜单管理、数据权限等能力的快速集成。触发词:"组织架构"、"部门管理"、"角色权限"、"RBAC"、"菜单管理"、"数据权限"、"org permission"、"role"、"menu"、"department"。

Overview

Publisherjiushiwon
Repositorywg-skills
Skill namefastapi-org-permission-module-skill
Stars
123
Forks
38
Bundled files
1
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 1 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by jiushiwon on GitHub. Read the source before you install it.

Installation

Install the Fastapi Org Permission Module Skill AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/jiushiwon/wg-skills/tree/main/vibeCoding/backend/python/fastapi-module/fastapi-org-permission-module-skill
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/jiushiwon/wg-skills.git /tmp/wg-skills
mkdir -p .claude/skills
cp -r /tmp/wg-skills/vibeCoding/backend/python/fastapi-module/fastapi-org-permission-module-skill .claude/skills/fastapi-org-permission-module-skill
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Fastapi Org Permission Module Skill in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Fastapi Org Permission Module Skill on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Fastapi Org Permission Module Skill is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

FastAPI Org Permission Module Skill

面向已有 FastAPI 项目的开发者,快速集成组织权限能力。

能力清单

能力说明
组织架构组织/部门管理
用户管理用户-部门-岗位关联
角色管理角色定义与权限分配
菜单管理前后端菜单配置
权限控制按钮/接口级权限
数据权限行级数据隔离

触发场景

用户说"帮我加权限"或"集成 RBAC"时触发。

核心实现

依赖配置

bash
pip install sqlalchemy python-jose passlib

数据模型

python
# models.py
from sqlalchemy import Column, BigInteger, String, Integer, Text, DateTime, Enum as SQLEnum
from sqlalchemy.sql import func
from database import Base
import enum

class RoleType(str, enum.Enum):
    SYSTEM = "system"
    CUSTOM = "custom"

class MenuType(str, enum.Enum):
    CATALOG = "catalog"
    MENU = "menu"
    BUTTON = "button"

class Org(Base):
    __tablename__ = "wg_org"
    
    id = Column(BigInteger, primary_key=True, autoincrement=True)
    name = Column(String(100), nullable=False)
    parent_id = Column(BigInteger, default=0)
    parent_ids = Column(String(500), default="0/")
    sort = Column(Integer, default=0)
    leader = Column(String(50))
    phone = Column(String(20))
    status = Column(Integer, default=1)
    created_at = Column(DateTime, server_default=func.now())

class Dept(Base):
    __tablename__ = "wg_dept"
    
    id = Column(BigInteger, primary_key=True, autoincrement=True)
    org_id = Column(BigInteger, nullable=False)
    parent_id = Column(BigInteger, default=0)
    name = Column(String(100), nullable=False)
    sort = Column(Integer, default=0)
    leader = Column(String(50))
    status = Column(Integer, default=1)
    created_at = Column(DateTime, server_default=func.now())

class User(Base):
    __tablename__ = "wg_user"
    
    id = Column(BigInteger, primary_key=True, autoincrement=True)
    username = Column(String(50), unique=True, nullable=False)
    password = Column(String(255), nullable=False)
    nickname = Column(String(100))
    dept_id = Column(BigInteger)
    post_id = Column(BigInteger)
    email = Column(String(100))
    phone = Column(String(20))
    status = Column(Integer, default=1)
    created_at = Column(DateTime, server_default=func.now())

class Role(Base):
    __tablename__ = "wg_role"
    
    id = Column(BigInteger, primary_key=True, autoincrement=True)
    name = Column(String(50), nullable=False)
    code = Column(String(50), unique=True, nullable=False)
    description = Column(String(200))
    type = Column(SQLEnum(RoleType), default=RoleType.CUSTOM)
    status = Column(Integer, default=1)
    created_at = Column(DateTime, server_default=func.now())

class Menu(Base):
    __tablename__ = "wg_menu"
    
    id = Column(BigInteger, primary_key=True, autoincrement=True)
    name = Column(String(50), nullable=False)
    parent_id = Column(BigInteger, default=0)
    path = Column(String(200))
    component = Column(String(200))
    icon = Column(String(50))
    sort = Column(Integer, default=0)
    type = Column(SQLEnum(MenuType), default=MenuType.MENU)
    permission = Column(String(100))
    status = Column(Integer, default=1)
    created_at = Column(DateTime, server_default=func.now())

# 关联表
class UserRole(Base):
    __tablename__ = "wg_user_role"
    
    user_id = Column(BigInteger, primary_key=True)
    role_id = Column(BigInteger, primary_key=True)

class RoleMenu(Base):
    __tablename__ = "wg_role_menu"
    
    role_id = Column(BigInteger, primary_key=True)
    menu_id = Column(BigInteger, primary_key=True)

服务层

python
# services/org_service.py
from typing import List, Optional

class OrgService:
    # 部门管理
    async def create_dept(self, dept: Dept) -> Dept:
        db.add(dept)
        db.commit()
        db.refresh(dept)
        return dept
    
    async def get_dept_tree(self) -> List[dict]:
        depts = db.query(Dept).all()
        return self._build_tree(depts)
    
    def _build_tree(self, depts: List[Dept]) -> List[dict]:
        """构建部门树"""
        tree = []
        dept_map = {d.id: d for d in depts}
        
        for dept in depts:
            if dept.parent_id == 0:
                tree.append(self._to_tree(dept, depts))
        return tree
    
    def _to_tree(self, dept: Dept, all_depts: List[Dept]) -> dict:
        children = [self._to_tree(d, all_depts) 
                   for d in all_depts if d.parent_id == dept.id]
        return {
            "id": dept.id,
            "name": dept.name,
            "children": children
        }

# services/permission_service.py
class PermissionService:
    # 获取用户权限
    async def get_user_permissions(self, user_id: int) -> List[str]:
        # 1. 获取用户角色
        role_ids = db.query(UserRole.role_id).filter(
            UserRole.user_id == user_id
        ).all()
        role_ids = [r[0] for r in role_ids]
        
        # 2. 获取角色菜单
        menu_ids = db.query(RoleMenu.menu_id).filter(
            RoleMenu.role_id.in_(role_ids)
        ).all()
        menu_ids = [m[0] for m in menu_ids]
        
        # 3. 获取菜单权限
        menus = db.query(Menu).filter(
            Menu.id.in_(menu_ids),
            Menu.permission.isnot(None)
        ).all()
        
        return [m.permission for m in menus]
    
    # 获取用户菜单
    async def get_user_menus(self, user_id: int) -> List[Menu]:
        role_ids = db.query(UserRole.role_id).filter(
            UserRole.user_id == user_id
        ).all()
        role_ids = [r[0] for r in role_ids]
        
        menus = db.query(Menu).filter(
            Menu.id.in_(
                db.query(RoleMenu.menu_id).filter(
                    RoleMenu.role_id.in_(role_ids)
                )
            ),
            Menu.status == 1
        ).all()
        
        return self._build_menu_tree(menus)
    
    def _build_menu_tree(self, menus: List[Menu]) -> List[dict]:
        """构建菜单树"""
        menu_map = {m.id: m for m in menus}
        tree = []
        
        for menu in menus:
            if menu.parent_id == 0:
                tree.append(self._to_menu_tree(menu, menus))
        return tree
    
    def _to_menu_tree(self, menu: Menu, all_menus: List[Menu]) -> dict:
        children = [self._to_menu_tree(m, all_menus)
                   for m in all_menus if m.parent_id == menu.id]
        return {
            "id": menu.id,
            "name": menu.name,
            "path": menu.path,
            "component": menu.component,
            "icon": menu.icon,
            "children": children if children else None
        }
    
    # 检查权限
    async def has_permission(self, user_id: int, permission: str) -> bool:
        perms = await self.get_user_permissions(user_id)
        return permission in perms

# 依赖注入
async def get_current_user_permissions(user_id: int = Depends(get_current_user)):
    perms = await permission_service.get_user_permissions(user_id)
    return perms

# 接口权限检查
def require_permission(permission: str):
    async def checker(perms: List[str] = Depends(get_current_user_permissions)):
        if permission not in perms:
            raise HTTPException(status_code=403, detail="权限不足")
    return checker

API 路由

python
# routers/org.py
from fastapi import APIRouter, Depends, HTTPException

router = APIRouter(prefix="/api/org", tags=["组织权限"])

@router.get("/dept/tree")
async def get_dept_tree():
    tree = await org_service.get_dept_tree()
    return ApiResponse.ok(tree)

@router.post("/dept")
async def create_dept(dept: DeptCreate):
    new_dept = await org_service.create_dept(Dept(**dept.dict()))
    return ApiResponse.ok(new_dept)

# routers/permission.py
@router.get("/menus")
async def get_user_menus(user_id: int = Depends(get_current_user)):
    menus = await permission_service.get_user_menus(user_id)
    return ApiResponse.ok(menus)

@router.get("/permissions")
async def get_user_permissions(user_id: int = Depends(get_current_user)):
    perms = await permission_service.get_user_permissions(user_id)
    return ApiResponse.ok(perms)

# 使用示例
@router.delete("/user/{user_id}")
async def delete_user(
    user_id: int,
    _: List[str] = Depends(require_permission("user:delete"))
):
    await user_service.delete_user(user_id)
    return ApiResponse.ok(None)

不做

  • 不负责 CAS 集成
  • 不处理 SSO
  • 不提供 UI 相关代码

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Fastapi Org Permission Module Skill AI skill do?

Python FastAPI 组织权限模块技能。面向已有 FastAPI 项目的开发者,提供组织架构、部门管理、角色权限、RBAC、菜单管理、数据权限等能力的快速集成。触发词:"组织架构"、"部门管理"、"角色权限"、"RBAC"、"菜单管理"、"数据权限"、"org permission"、"role"、"menu"、"department"。

Why use Fastapi Org Permission Module Skill on TypingMind?

Because you install it once and use it with any model. Fastapi Org Permission Module Skill is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Fastapi Org Permission Module Skill in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/jiushiwon/wg-skills/tree/main/vibeCoding/backend/python/fastapi-module/fastapi-org-permission-module-skill. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Fastapi Org Permission Module Skill?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Fastapi Org Permission Module Skill?

As many as you like. As long as a model supports skills, you can use Fastapi Org Permission Module Skill with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Fastapi Org Permission Module Skill AI skill free?

Yes. It is published on GitHub by jiushiwon under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇