Skip to content

Commit

Permalink
Site updated: 2023-08-04 19:30:28
Browse files Browse the repository at this point in the history
  • Loading branch information
cxzlw committed Aug 4, 2023
1 parent e58c24b commit 3578cc4
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion 2023/07/05/trace-of-line-01/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta property="og:description" content="不存在的历史,勾起了石月仙的注意,随着找寻真相的深入,一个隐瞒了全世界的阴谋浮出水面。而对于人类,阴谋何来,何从,何去?「第三次科技革命后,人类进入信息时代,信息化开始影响人类的历史进程……」「为什么初中高中上过的还要再上一遍啊?我都快烦死了。」石月仙在心中自言自语道,眼睛无神地看着教授在全息屏上指指点点。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-07-05T14:20:06.000Z">
<meta property="article:modified_time" content="2023-08-04T11:27:23.912Z">
<meta property="article:modified_time" content="2023-08-04T11:30:10.657Z">
<meta property="article:author" content="cxzlw">
<meta property="article:tag" content="飞石">
<meta property="article:tag" content="小说">
Expand Down
2 changes: 1 addition & 1 deletion 2023/07/05/zhihu-aac-old/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://blog.cxzlw.top/img/image.png">
<meta property="article:published_time" content="2023-07-04T17:49:31.000Z">
<meta property="article:modified_time" content="2023-08-04T11:27:23.916Z">
<meta property="article:modified_time" content="2023-08-04T11:30:10.657Z">
<meta property="article:author" content="cxzlw">
<meta property="article:tag" content="cxzlw">
<meta property="article:tag" content="知乎">
Expand Down
2 changes: 1 addition & 1 deletion 2023/07/06/zerotier-planet-convert/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta property="og:description" content="由于国内特殊的网络原因,Zerotier 官方提供的 Planet 用户体验不佳。为此,不少人选择自建私有 Moon,甚至私有 Planet 服务器。然而,正如官方文档所说,使用私有 Planet 服务器会使你的节点无法找到其他的标准节点。本文试图提出一种方案在使用私有 Planet 服务器的同时与标准节点通信。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-07-06T04:37:41.000Z">
<meta property="article:modified_time" content="2023-08-04T11:27:23.912Z">
<meta property="article:modified_time" content="2023-08-04T11:30:10.657Z">
<meta property="article:author" content="cxzlw">
<meta property="article:tag" content="Zerotier">
<meta property="article:tag" content="自建Planet">
Expand Down
2 changes: 1 addition & 1 deletion 2023/07/10/trace-of-line-02/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta property="og:description" content="不存在的历史,勾起了石月仙的注意,随着找寻真相的深入,一个隐瞒了全世界的阴谋浮出水面。而对于人类,阴谋何来,何从,何去?「你家里关于知识大革命真实历史的藏书消失了,不仅如此,你对于知识大革命原有的记忆也消失了。这说明什么?」「说明有人想彻底地掩埋真相?」">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-07-10T15:01:06.000Z">
<meta property="article:modified_time" content="2023-08-04T11:27:23.912Z">
<meta property="article:modified_time" content="2023-08-04T11:30:10.657Z">
<meta property="article:author" content="cxzlw">
<meta property="article:tag" content="飞石">
<meta property="article:tag" content="小说">
Expand Down
12 changes: 6 additions & 6 deletions 2023/08/04/permission-system-design-share/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
<meta name="author" content="cxzlw">
<meta name="keywords" content="创新者老王,创新者.老王,博客,技术博客,老王,创新者,Earthno1,FatalError">

<meta name="description" content="最近在参与某 OJ 的开发,过程中我们需要一个权限系统。作为一个热爱 MC 的开发者,我很喜欢 luckperms 的设计,于是这个小东西就出来了。在这里给大家分享我们的权限系统设计。 为什么不使用现成的库? 如上文所说,我很喜欢 luckperms 的 Group,Node,Route 我们希望整个项目使用 PonyORM 我们希望这个库最好不要与某个 Web Framework 强关联,例如现">
<meta name="description" content="最近在参与某 OJ 的开发,过程中我们需要一个权限系统。作为一个热爱 MC 的开发者,我很喜欢 luckperms 的设计,于是这个小东西就出来了。在这里给大家分享我们的权限系统设计。">
<meta property="og:type" content="article">
<meta property="og:title" content="分享一个权限系统的设计">
<meta property="og:url" content="https://blog.cxzlw.top/2023/08/04/permission-system-design-share/index.html">
<meta property="og:site_name" content="创新者.老王的博客">
<meta property="og:description" content="最近在参与某 OJ 的开发,过程中我们需要一个权限系统。作为一个热爱 MC 的开发者,我很喜欢 luckperms 的设计,于是这个小东西就出来了。在这里给大家分享我们的权限系统设计。 为什么不使用现成的库? 如上文所说,我很喜欢 luckperms 的 Group,Node,Route 我们希望整个项目使用 PonyORM 我们希望这个库最好不要与某个 Web Framework 强关联,例如现">
<meta property="og:description" content="最近在参与某 OJ 的开发,过程中我们需要一个权限系统。作为一个热爱 MC 的开发者,我很喜欢 luckperms 的设计,于是这个小东西就出来了。在这里给大家分享我们的权限系统设计。">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-08-04T07:32:59.000Z">
<meta property="article:modified_time" content="2023-08-04T11:27:23.912Z">
<meta property="article:modified_time" content="2023-08-04T11:30:10.657Z">
<meta property="article:author" content="cxzlw">
<meta property="article:tag" content="创新者老王">
<meta property="article:tag" content="创新者.老王">
Expand Down Expand Up @@ -246,7 +246,7 @@
<span class="post-meta mr-2">
<i class="iconfont icon-chart"></i>

4.6k
3.8k

</span>

Expand All @@ -257,7 +257,7 @@



39 分钟
32 分钟

</span>

Expand Down Expand Up @@ -347,7 +347,7 @@ <h3 id="models-user-py"><a href="#models-user-py" class="headerlink" title="mode

<h3 id="models-permission-group-py"><a href="#models-permission-group-py" class="headerlink" title="models&#x2F;permission_group.py"></a>models&#x2F;permission_group.py</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">from</span> pony.orm <span class="hljs-keyword">import</span> Required, <span class="hljs-type">Set</span>, db_session<br><br><span class="hljs-keyword">from</span> .db <span class="hljs-keyword">import</span> db<br><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">PermissionGroup</span>(db.Entity):<br> name = Required(<span class="hljs-built_in">str</span>, unique=<span class="hljs-literal">True</span>)<br> weight = Required(<span class="hljs-built_in">int</span>)<br> nodes = <span class="hljs-type">Set</span>(<span class="hljs-string">&quot;PermissionNode&quot;</span>)<br> members = <span class="hljs-type">Set</span>(<span class="hljs-string">&quot;User&quot;</span>)<br> parents = <span class="hljs-type">Set</span>(<span class="hljs-string">&quot;PermissionGroup&quot;</span>, reverse=<span class="hljs-string">&quot;childs&quot;</span>)<br> childs = <span class="hljs-type">Set</span>(<span class="hljs-string">&quot;PermissionGroup&quot;</span>, reverse=<span class="hljs-string">&quot;parents&quot;</span>)<br><br><span class="hljs-meta"> @classmethod</span><br><span class="hljs-meta"> @db_session</span><br> <span class="hljs-keyword">def</span> <span class="hljs-title function_">instance</span>(<span class="hljs-params">cls, name, weight=<span class="hljs-literal">None</span></span>):<br> <span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string"> Return an PermissionGroup instance.</span><br><span class="hljs-string"></span><br><span class="hljs-string"> If a PermissionGroup with the name exists, it will directly return the group,</span><br><span class="hljs-string"> with new weight value. It is noticeable that, if weight is not given, it won&#x27;t be changed.</span><br><span class="hljs-string"></span><br><span class="hljs-string"> Or, it will create a new PermissionGroup with the given name and weight value.</span><br><span class="hljs-string"> Notice that if the weight is not given here, an ValueError will be thrown.</span><br><span class="hljs-string"></span><br><span class="hljs-string"> &quot;&quot;&quot;</span><br> result = cls.get(name=name)<br> <span class="hljs-keyword">if</span> result <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:<br> <span class="hljs-keyword">if</span> weight <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:<br> <span class="hljs-keyword">raise</span> ValueError<br> <span class="hljs-keyword">return</span> cls(name=name, weight=weight)<br> <span class="hljs-keyword">if</span> weight <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:<br> result.weight = weight<br> <span class="hljs-keyword">return</span> result<br><br></code></pre></td></tr></table></figure>

<h3 id="models-permission-node-py"><a href="#models-permission-node-py" class="headerlink" title="models&#x2F;permission_node.py"></a>models&#x2F;permission_node.py</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">from</span> pony.orm <span class="hljs-keyword">import</span> Required, db_session<br><br><span class="hljs-keyword">from</span> .db <span class="hljs-keyword">import</span> db<br><span class="hljs-keyword">from</span> .permission_group <span class="hljs-keyword">import</span> PermissionGroup<br><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">PermissionNode</span>(db.Entity):<br> permission = Required(<span class="hljs-built_in">str</span>)<br> value = Required(<span class="hljs-built_in">bool</span>)<br> owner = Required(PermissionGroup)<br><br><span class="hljs-meta"> @classmethod</span><br><span class="hljs-meta"> @db_session</span><br> <span class="hljs-keyword">def</span> <span class="hljs-title function_">instance</span>(<span class="hljs-params">cls, permission, value=<span class="hljs-literal">None</span>, owner=<span class="hljs-literal">None</span></span>):<br> <span class="hljs-string">&quot;&quot;&quot;</span><br><span class="hljs-string"> Return an PermissionNode instance.</span><br><span class="hljs-string"></span><br><span class="hljs-string"> If a PermissionNode with the permission exists, it will directly return the</span><br><span class="hljs-string"> node, with new weight and owner value. It is noticeable that, if value</span><br><span class="hljs-string"> or owner are not given, it won&#x27;t be changed.</span><br><span class="hljs-string"></span><br><span class="hljs-string"> Or, it will create a new PermissionNode with the given permission, value, and</span><br><span class="hljs-string"> owner value. Notice that if the weight or owner are not given here, an</span><br><span class="hljs-string"> ValueError will be thrown.</span><br><span class="hljs-string"></span><br><span class="hljs-string"> &quot;&quot;&quot;</span><br> result = cls.get(permission=permission)<br> <span class="hljs-keyword">if</span> result <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:<br> <span class="hljs-keyword">if</span> value <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:<br> <span class="hljs-keyword">raise</span> ValueError<br> <span class="hljs-keyword">if</span> owner <span class="hljs-keyword">is</span> <span class="hljs-literal">None</span>:<br> <span class="hljs-keyword">raise</span> ValueError<br> <span class="hljs-keyword">return</span> cls(permission=permission, value=value, owner=owner)<br> <span class="hljs-keyword">if</span> value <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:<br> result.value = value<br> <span class="hljs-keyword">if</span> owner <span class="hljs-keyword">is</span> <span class="hljs-keyword">not</span> <span class="hljs-literal">None</span>:<br> result.owner = owner<br> <span class="hljs-keyword">return</span> result<br><br></code></pre></td></tr></table></figure>
<h3 id="models-permission-node-py"><a href="#models-permission-node-py" class="headerlink" title="models&#x2F;permission_node.py"></a>models&#x2F;permission_node.py</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">from</span> pony.orm <span class="hljs-keyword">import</span> Required, db_session<br><br><span class="hljs-keyword">from</span> .db <span class="hljs-keyword">import</span> db<br><span class="hljs-keyword">from</span> .permission_group <span class="hljs-keyword">import</span> PermissionGroup<br><br><br><span class="hljs-keyword">class</span> <span class="hljs-title class_">PermissionNode</span>(db.Entity):<br> permission = Required(<span class="hljs-built_in">str</span>)<br> value = Required(<span class="hljs-built_in">bool</span>)<br> owner = Required(PermissionGroup)<br><br></code></pre></td></tr></table></figure>

<h3 id="permission-init-py"><a href="#permission-init-py" class="headerlink" title="permission&#x2F;__init__.py"></a>permission&#x2F;__init__.py</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><code class="hljs python"><span class="hljs-keyword">from</span> queue <span class="hljs-keyword">import</span> Queue<br><br><span class="hljs-keyword">from</span> models <span class="hljs-keyword">import</span> User<br><span class="hljs-keyword">from</span> pony.orm <span class="hljs-keyword">import</span> select<br><br><br><span class="hljs-keyword">def</span> <span class="hljs-title function_">check_permission</span>(<span class="hljs-params">user: User, permission</span>):<br> queue = Queue()<br> weight = <span class="hljs-built_in">float</span>(<span class="hljs-string">&quot;-inf&quot;</span>)<br> value = <span class="hljs-literal">False</span><br> <span class="hljs-keyword">for</span> group <span class="hljs-keyword">in</span> user.permission_groups:<br> queue.put(group)<br> <span class="hljs-keyword">while</span> <span class="hljs-keyword">not</span> queue.empty():<br> group = queue.get()<br> <span class="hljs-keyword">for</span> g <span class="hljs-keyword">in</span> group.parents:<br> queue.put(g)<br> <span class="hljs-keyword">if</span> group.weight &lt; weight:<br> <span class="hljs-keyword">continue</span><br> values = select(node.value <span class="hljs-keyword">for</span> node <span class="hljs-keyword">in</span> group.nodes <span class="hljs-keyword">if</span> node.permission == permission)<br> <span class="hljs-keyword">for</span> v <span class="hljs-keyword">in</span> values:<br> value = v<br> weight = group.weight<br> <span class="hljs-keyword">return</span> value<br><br></code></pre></td></tr></table></figure>

Expand Down
2 changes: 1 addition & 1 deletion 2023/08/04/test-latex/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta property="og:description" content="$$E&#x3D;mc^2$$">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-08-04T06:35:08.000Z">
<meta property="article:modified_time" content="2023-08-04T11:27:23.912Z">
<meta property="article:modified_time" content="2023-08-04T11:30:10.657Z">
<meta property="article:author" content="cxzlw">
<meta property="article:tag" content="创新者老王">
<meta property="article:tag" content="创新者.老王">
Expand Down
2 changes: 1 addition & 1 deletion about/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<meta property="og:description" content="欢迎来到我的博客">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2023-07-02T17:01:41.000Z">
<meta property="article:modified_time" content="2023-08-04T11:27:23.916Z">
<meta property="article:modified_time" content="2023-08-04T11:30:10.657Z">
<meta property="article:author" content="cxzlw">
<meta property="article:tag" content="创新者老王">
<meta property="article:tag" content="创新者.老王">
Expand Down
Loading

0 comments on commit 3578cc4

Please sign in to comment.