Git Product home page Git Product logo

Comments (1)

iceboy233 avatar iceboy233 commented on September 19, 2024

In vj4, there are two things called permission and privilege. Permission is per-domain and privilege is per-system (for the entire site).

In code we usually assert permission and privilege requirements by applying decorators on view handlers. For example, in vj4/view/discussion.py:50:

@app.route('/discuss/{node_or_pid}/create', 'discussion_create')
class DiscussionCreateView(base.View):
  @base.require_priv(builtin.PRIV_USER_PROFILE)
  @base.require_perm(builtin.PERM_CREATE_DISCUSSION)
  @base.route_argument
  @base.sanitize
  async def get(self, *, node_or_pid: document.convert_doc_id):
    vnode = await discussion.get_vnode(self.domain_id, node_or_pid)

The discussion_create view requires PRIV_USER_PROFILE privilege and PERM_CREATE_DISCUSSION permission.

Privileges are directly stored in the user collection, where most user's privilege should be 4, which is PRIV_USER_PROFILE, which means the user has access to its user profile. Guest user (hardcoded in vj4/model/builtin.py) doesn't have PRIV_USER_PROFILE, but it has PRIV_REGISTER_USER.

My UID is -4, and I can run the following command in MongoDB shell to see my privilege.

> db.user.findOne({_id: -4}, {priv: 1})
{ "_id" : -4, "priv" : 4 }

Say you want to play with the judge playground, which is an interactive web page where you can behave like a judger. The judge playground requires PRIV_READ_RECORD_CODE and builtin.PRIV_WRITE_RECORD which normal users don't have. Since

PRIV_USER_PROFILE (4) + PRIV_READ_RECORD_CODE (16) + PRIV_WRITE_RECORD (64) = 84

You can run the following command in MongoDB shell to change the privilege.

> db.user.updateOne({_id: -4}, {$set: {priv: NumberInt(84)}})
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 }

And then you can verify by:

> db.user.findOne({_id: -4}, {priv: 1})
{ "_id" : -4, "priv" : 84 }

Permission is another thing, which is not fully implemented and not useful for now.

from vj4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.